package com.dpac.core.bean;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.net.InetAddress;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.persistence.Column;
import javax.persistence.JoinColumn;
import javax.persistence.Table;
import javax.servlet.ServletContext;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.dpac.core.exception.ProcessException;
import com.dpac.core.util.ArithUtils;
import com.dpac.core.util.DesUtils;
import com.dpac.core.util.HttpClientUtils;
import com.dpac.core.util.JsonUtils;
import com.dpac.core.util.MD5Utils;
import com.dpac.core.util.PropertyUtils;
import com.dpac.core.vo.ResultVo;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @title 公共Bean
 * @description 存放项目的公共方法
 * @creator Hearken
 * @date 2011-12-20 下午05:14:00
 */
public class CommonBean {

	public static final String PROJECT_CHARSET = "UTF-8";
	public static final String UPDATE_STRING_NULL_VALUE = "string_null_value";
	public static final int UPDATE_INTEGER_NULL_VALUE = Integer.MIN_VALUE;
	public static final long UPDATE_LONG_NULL_VALUE = Long.MIN_VALUE;
	public static final double UPDATE_DOUBLE_NULL_VALUE = Double.MIN_VALUE;
	public static final float UPDATE_FLOAT_NULL_VALUE = Float.MIN_VALUE;
	private static String filePath;// 资源父目录

	/**
	 * 资源父目录(只用于全局初始化)
	 * 
	 * @param sFilePath
	 */
	public static void setFilePath(String sFilePath) {
		filePath = sFilePath;
	}

	// /**
	// * 获取页面路径
	// * @param request
	// * @return
	// */
	// public static String getPageUrl(HttpServletRequest request) {
	// return getPageUrl(request, "http");
	// }

	/**
	 * 获取页面路径
	 * 
	 * @param request
	 * @return
	 */
	public static String getPageUrl(HttpServletRequest request) {
		String sServiceName = request.getServerName();
		String sScheme = "", sServicePort = "";
		if (80 == request.getServerPort()) {
			sScheme = "http";
		} else if (443 == request.getServerPort()) {
			sScheme = "https";
		} else {
			sScheme = "http";
			sServicePort = String.valueOf(request.getServerPort());
		}
		String sFullPath = sScheme + "://" + sServiceName;
		if (!"".equals(sServicePort))
			sFullPath += ":" + request.getServerPort();
		sFullPath += request.getContextPath();
		return sFullPath;
	}

	/**
	 * 检查数字
	 * 
	 * @param sStr
	 * @param iLength
	 * @return
	 */
	public static boolean checkDigital(String sStr, int iLength) {
		boolean bFlag = false;
		String sPat = "(^[0-9]{" + iLength + "}$)";
		if (iLength <= 0) {
			sPat = "(^[0-9]*$)";// 不限制长度
		}
		Pattern idNumPattern = Pattern.compile(sPat);
		Matcher idNumMatcher = idNumPattern.matcher(sStr);
		if (idNumMatcher.matches()) {
			bFlag = true;
		}
		return bFlag;
	}

	/**
	 * 获取中奖范围
	 * 
	 * @param sTempArr[][]{奖项id,中奖几率},{奖项id,中奖机率}...
	 * @return返回“随机值;奖项id|0~10;奖项id|11~50...”
	 */
	public static String getLotteryRange(String[][] sTempArr) {
		String sRange = "";
		try {
			long lRandomValue = 100;
			if (sTempArr == null || sTempArr.length < 1)
				return sRange;
			// 循环将最小的机率取出
			double dMinValue = 0.00, dTempValue = 0.00;
			for (int i = 0; i < sTempArr.length; i++) {
				String[] sArr = sTempArr[i];
				if (sArr == null || sArr.length < 2 || sArr[1] == null)
					continue;
				dTempValue = Double.valueOf(sArr[1]);
				if (dMinValue == 0.00)
					dMinValue = dTempValue;
				if (dMinValue > dTempValue && dTempValue != 0.00) {
					dMinValue = dTempValue;
				}
			}
			// 判断最小值是否小于1，如果是则计算出倍数
			Long lMultiple = 1L;
			if (dMinValue < 1 && dMinValue != 0) {
				// 倍数说明：1%=百分之一，0.1%=千分之一，0.01%=万分之一，0.001%=十万分之一，以此类推
				double dTempMin = 0.0001;
				do {
					lMultiple++;
					dTempMin = ArithUtils.mul(dMinValue, Math.pow(10.00, lMultiple.doubleValue()));
				} while (dTempMin < 1 && lMultiple < 6);
				lMultiple = (long) Math.pow(10.00, lMultiple.doubleValue());
				lRandomValue = lRandomValue * lMultiple;
			}
			// 生成各个奖项的范围
			String sId = "", sTempRange = "";
			long lTempValue = 0l, lLastTempValue = 0l;
			for (int i = 0; i < sTempArr.length; i++) {
				String[] sArr = sTempArr[i];
				if (sArr == null || sArr.length < 2 || sArr[1] == null)
					continue;
				sId = sArr[0];
				dTempValue = Double.valueOf(sArr[1]);
				lTempValue = Math.round(ArithUtils.mul(dTempValue, lMultiple.doubleValue()));// 四舍五入
				if (i == 0) {
					sTempRange += sId + "|0~" + lTempValue;
				} else {
					sTempRange += ";" + sId + "|" + lLastTempValue + "~" + (lLastTempValue + lTempValue);
				}
				lLastTempValue = lLastTempValue + lTempValue;
			}
			if (!"".equals(sTempRange)) {
				sRange = lRandomValue + ";" + sTempRange;
			}
		} catch (Exception e) {
			System.out.println("获取中奖范围异常=" + e.getMessage());
			e.printStackTrace();
		}
		System.out.println("获取中奖范围=" + sRange);
		return sRange;
	}

	/**
	 * 获取中奖结果
	 * 
	 * @param sLotteryRange:随机值;奖项id|0~10;奖项id|11~50...
	 * @return返回奖项的id
	 */
	public static String getLotteryResult(String sLotteryRange) {
		String sLotteryId = "";
		try {
			if (sLotteryRange == null || sLotteryRange.indexOf(";") < 0)
				return sLotteryId;
			String[] sRangeArr = sLotteryRange.split(";");
			if (sRangeArr == null || sRangeArr.length < 2)
				return sLotteryId;
			int iRandomValue = CommonBean.stringToInteger(sRangeArr[0]);
			Random random = new Random();
			int iResult = random.nextInt(iRandomValue) + 1;
			String sId = "", sRange = "";
			long lStartValue = 0, lEndValue = 0;
			for (int i = 1; i < sRangeArr.length; i++) {
				String sStr = sRangeArr[i];
				if (sStr == null || "".equals(sStr) || sStr.indexOf("|") < 0 || sStr.indexOf("~") < 0)
					continue;
				sId = sStr.substring(0, sStr.indexOf("|"));
				sRange = sStr.substring(sStr.indexOf("|") + 1, sStr.length());
				lStartValue = CommonBean.stringToLong(sRange.substring(0, sRange.indexOf("~")));
				lEndValue = CommonBean.stringToLong(sRange.substring(sRange.indexOf("~") + 1, sRange.length()));
				// 判断随机值是否在奖项的范围里，如果是则中奖
				if (lStartValue == 0 && lEndValue == 0)
					continue;// 机率为0就直接跳过
				if (lStartValue < iResult && iResult <= lEndValue) {
					sLotteryId = sId;
					break;
				}
			}
		} catch (Exception e) {
			System.out.println("获取中奖结果异常=" + e.getMessage());
			e.printStackTrace();
		}
		if ("".equals(sLotteryId))
			sLotteryId = "-1";// -1为谢谢参与
		System.out.println("获取中奖结果=" + sLotteryId);
		return sLotteryId;
	}

	/**
	 * 获取自定义编号没有4数字
	 * 
	 * @param lNumber
	 * @return
	 */
	public static String getCustomNumberNo4(long lNumber) {
		String[] sStrArr = new String[] { "0", "1", "2", "3", "5", "6", "7", "8", "9" };
		String sNewStr = "";
		if (lNumber == 0)
			return sStrArr[0];
		ArrayList<String> lstResult = new ArrayList<String>();
		boolean bRunning = true;
		int iTemp = 0;
		while (bRunning) {
			iTemp = (int) lNumber % 9;
			if (iTemp == 0 && lNumber < 9) {
				iTemp = 8;
			}
			lstResult.add(sStrArr[iTemp]);
			lNumber = lNumber / 9;
			if (lNumber <= 0)
				bRunning = false;
		}
		if (lstResult.size() < 1)
			return "";
		for (int i = lstResult.size() - 1; i >= 0; i--) {
			sNewStr += lstResult.get(i);
		}
		return sNewStr;
	}

	/**
	 * 获得本季度开始日期和结束日期
	 * 
	 * @param sType:1-本月，-1-上月
	 * @return
	 */
	public static String[] getSeasonStartAndEnd(String sType) {
		String[] sWeekArr = null;
		int month = Integer.valueOf(CommonBean.getNowTime("M"));
		int array[][] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } };

		int season = 1, year = 0;
		if (month >= 1 && month <= 3) {
			season = 1;
		}
		if (month >= 4 && month <= 6) {
			season = 2;
		}
		if (month >= 7 && month <= 9) {
			season = 3;
		}
		if (month >= 10 && month <= 12) {
			season = 4;
		}
		if ("-1".equals(sType)) {
			season -= 1;
			if (season <= 0) {
				// 推算到上年最后一季度
				season = 4;
				year = -1;
			}
		}
		int start_month = array[season - 1][0];
		int end_month = array[season - 1][2];

		Date date = new Date();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy");// 可以方便地修改日期格式
		String years = dateFormat.format(date);
		int years_value = Integer.parseInt(years) + year;
		int end_days = getLastDayOfMonth(years_value, end_month);
		String sStartDate = years_value + "-" + buildNumber("" + start_month, 2) + "-01";
		String sEndDate = years_value + "-" + buildNumber("" + end_month, 2) + "-" + buildNumber("" + end_days, 2);
		sWeekArr = new String[] { sStartDate, sEndDate };
		return sWeekArr;
	}

	/**
	 * 获取某年某月的最后一天
	 * 
	 * @param year
	 *            年
	 * @param month
	 *            月
	 * @return 最后一天
	 */
	private static int getLastDayOfMonth(int year, int month) {
		if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
			return 31;
		}
		if (month == 4 || month == 6 || month == 9 || month == 11) {
			return 30;
		}
		if (month == 2) {
			if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
				return 29;
			} else {
				return 28;
			}
		}
		return 0;
	}

	/**
	 * 获取月的开始日期和结束日期
	 * 
	 * @param sType:1-本月，-1-上月
	 * @return
	 */
	public static String[] getMonthStartAndEnd(String sType) {
		String[] sWeekArr = null;
		Date dteStart = null, dteEnd = null;
		if ("-1".equals(sType)) {
			Calendar lastDate = Calendar.getInstance();
			lastDate.set(Calendar.DATE, 1);// 设为当前月的1号
			lastDate.add(Calendar.MONTH, -1);// 减一个月，变为上月的1号
			dteStart = lastDate.getTime();
			lastDate.roll(Calendar.DATE, -1);// 日期回滚一天，也就是本月最后一天
			dteEnd = lastDate.getTime();
		} else {
			Calendar c = new GregorianCalendar();
			c.setTime(new Date());
			c.set(Calendar.DAY_OF_MONTH, 1);
			dteStart = c.getTime();
			c.set(Calendar.DAY_OF_MONTH, 1);
			c.add(Calendar.MONTH, 1);
			c.add(Calendar.DAY_OF_MONTH, -1);
			dteEnd = c.getTime();
		}
		sWeekArr = new String[] { String.format("%1$tY-%1$tm-%1$td", dteStart),
				String.format("%1$tY-%1$tm-%1$td", dteEnd) };
		return sWeekArr;
	}

	/**
	 * 获取周的开始日期和结束日期
	 * 
	 * @param sType:1-本周，-1-上周
	 * @return
	 */
	public static String[] getWeekStartAndEnd(String sType) {
		String[] sWeekArr = null;
		Date dteStart = null, dteEnd = null;
		if ("-1".equals(sType)) {
			int mondayPlus = 0;
			Calendar cd = Calendar.getInstance();
			// 获得今天是一周的第几天，星期日是第一天，星期二是第二天...
			int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK) - 1;
			if (dayOfWeek == 1) {
				mondayPlus = 0;
			} else if (dayOfWeek == 0) {
				mondayPlus = dayOfWeek - 6;
			} else {
				mondayPlus = 1 - dayOfWeek;
			}
			GregorianCalendar currentDate = new GregorianCalendar();
			GregorianCalendar currentDate2 = new GregorianCalendar();
			currentDate.add(GregorianCalendar.DATE, mondayPlus + 7 * -1);
			dteStart = currentDate.getTime();
			currentDate2.add(GregorianCalendar.DATE, mondayPlus - 1);
			dteEnd = currentDate2.getTime();
		} else {
			Calendar c = new GregorianCalendar();
			c.setFirstDayOfWeek(Calendar.MONDAY);
			c.setTime(new Date());
			c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek());
			dteStart = c.getTime();
			c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6);
			dteEnd = c.getTime();
		}
		sWeekArr = new String[] { String.format("%1$tY-%1$tm-%1$td", dteStart),
				String.format("%1$tY-%1$tm-%1$td", dteEnd) };
		return sWeekArr;
	}

	/**
	 * 金钱转换为金币
	 * 
	 * @param dMoney
	 * @return
	 */
	public static int moneyToGold(Double dMoney) {
		int iGold = 0;
		if (dMoney == null || dMoney == 0.00)
			return iGold;
		try {
			iGold = (int) (dMoney * 100.00);
		} catch (Exception e) {

		}
		return iGold;
	}

	/**
	 * 金币转换为 金钱
	 * 
	 * @param dMoney
	 * @return
	 */
	public static double goldToMoney(Integer iGlod) {
		double dMoney = 0.00;
		if (iGlod == null || iGlod == 0)
			return dMoney;
		try {
			dMoney = ArithUtils.div((double) iGlod, 100.00);
		} catch (Exception e) {

		}
		return dMoney;
	}

	/**
	 * 获取两日期间相差的天数(不计当天，例如：2009-04-05 200-04-05 返回0天)
	 * 
	 * @param bDate
	 * @param eDate
	 * @return
	 */
	public static int getDiscrepantDay(Date dBeginDate, Date dEndDate) {
		int days = 0;
		try {
			if (dBeginDate == null || dEndDate == null) {
				return days;
			}
			dBeginDate = formatDate(dBeginDate, "yyyy-MM-dd");
			dEndDate = formatDate(dEndDate, "yyyy-MM-dd");

			Calendar bc = Calendar.getInstance();
			bc.setTime(dBeginDate);
			Calendar ec = Calendar.getInstance();
			ec.setTime(dEndDate);

			double totalMillis = ec.getTimeInMillis() - bc.getTimeInMillis();
			double oneDayMillis = 24 * 60 * 60 * 1000;
			double resultMillis = totalMillis / oneDayMillis;
			days = (int) resultMillis;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return days;
	}

	/**
	 * 格式化日期
	 * 
	 * @param date
	 * @param format
	 * @return
	 */
	public static Date formatDate(Date date, String format) {
		Date newDate = null;
		if (date == null) {
			return newDate;
		}
		if (format == null || "".equals(format)) {
			format = "yyyy-MM-dd";
		}
		try {
			SimpleDateFormat dateFormat = new SimpleDateFormat(format);
			String sDate = dateFormat.format(date);
			newDate = dateFormat.parse(sDate);
		} catch (Exception e) {
			e.printStackTrace();
			newDate = date;
		}
		return newDate;
	}

	/**
	 * 两时间比较
	 * 
	 * @param date1
	 * @param date2
	 * @return 1(date1>date2) 0(date1=date2) -1(date1<date2)
	 */
	public static int compareDate(Date date1, Date date2) {
		if (date1 == null && date2 != null) {
			return 1;
		}
		if (date1 != null && date2 == null) {
			return -1;
		}
		if (date1.getTime() > date2.getTime()) {
			return 1;
		} else if (date1.getTime() == date2.getTime()) {
			return 0;
		} else {
			return -1;
		}
	}

	/**
	 * 为日期添加秒
	 * 
	 * @param date：日期
	 * @param second：秒
	 * @return
	 */
	public static Date dateAddSecond(Date date, int second) {
		try {
			Calendar bc = Calendar.getInstance();
			bc.setTime(date);
			bc.add(Calendar.SECOND, second);
			return bc.getTime();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return date;
	}

	/**
	 * 为日期添加月
	 * 
	 * @param date:日期
	 * @param months:月
	 * @return
	 */
	public static Date dateAddMonth(Date date, int months) {
		try {
			Calendar bc = Calendar.getInstance();
			bc.setTime(date);
			bc.add(Calendar.MONTH, months);
			return bc.getTime();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return date;
	}

	/**
	 * 为日期添加秒
	 * 
	 * @param sDate：日期(格式yyyy-MM-dd
	 *            HH:mm:ss)
	 * @param second：秒
	 * @return
	 */
	public static String dateAddSecond(String sDate, int second, String format) {
		if (sDate.length() < 19)
			return "";
		if (format == null || "".equals(format)) {
			format = "yyyy-MM-dd HH:mm:ss";
		}
		Date date = CommonBean.stringToDate(sDate);
		String sNewDate = CommonBean.dateToString(dateAddSecond(date, second), format);
		return sNewDate;
	}

	/**
	 * 为日期添加月
	 * 
	 * @param sDate:日期
	 * @param months:月
	 * @return
	 */
	public static String dateAddMonth(String sDate, int months) {
		if (sDate == null || "".equals(sDate))
			return null;
		Date date = CommonBean.stringToDate(sDate);
		// Date date = CommonBean.stringChangeToDate(sDate);
		String sNewDate = CommonBean.dateToString(dateAddMonth(date, months));
		return sNewDate;
	}

	/**
	 * 获取T+x的时间
	 * 
	 * @param sStr:要加多少天,日期的格式
	 * @return
	 */
	public static String getTxTime(String sStr) {
		String sTime = "";
		if (sStr == null || sStr.indexOf(",") < 0 || sStr.split(",").length < 2) {
			return getNowTime();
		}
		String[] sStrArr = sStr.split(",");
		sTime = getNowTime(sStrArr[1]);
		sTime = addDate(sTime, stringToInteger(sStrArr[0]), sStrArr[1]);
		return sTime;
	}

	/**
	 * 获取年龄
	 * 
	 * @param birthday
	 *            出生日期
	 * @param type
	 *            1：实龄 2：虚龄
	 * @return
	 */
	public static String getAge(String birthday, int type) {
		String sAge = "0";
		if (birthday == null || "".equals(birthday))
			return "";
		try {
			int age = 0;
			String sYear = "", sMonth = "", sDay = "";
			if (birthday.length() < 4) {
				return sAge;
			}
			String[] arrBirthday = birthday.split("-");
			if (arrBirthday.length >= 1) {
				sYear = arrBirthday[0];
			}
			if (arrBirthday.length >= 2) {
				sMonth = arrBirthday[1];
			}
			if (arrBirthday.length >= 3) {
				sDay = arrBirthday[2];
			}
			int iYear = 0, iMonth = 0, iDay = 0;
			if (!"".equals(sYear)) {
				iYear = Integer.parseInt(sYear);
			}
			if (!"".equals(sMonth)) {
				iMonth = Integer.parseInt(sMonth);
			}
			if (!"".equals(sDay)) {
				iDay = Integer.parseInt(sDay);
			}
			Calendar calendar = Calendar.getInstance();
			int nowYear = calendar.get(Calendar.YEAR);
			int nowMonth = calendar.get(Calendar.MONTH) + 1;
			int nowDay = calendar.get(Calendar.DAY_OF_MONTH);
			if (iYear != 0) {
				age = nowYear - iYear;
			}
			if (1 == type) {// 1：实龄
				if (iMonth > nowMonth || (iMonth == nowMonth && iDay > nowDay)) {
					age -= 1;
				}
			}
			sAge = String.valueOf(age);
		} catch (Exception e) {
			System.out.println("获取年龄异常=" + e.getMessage());
		}
		return sAge;
	}

	/**
	 * 增加日期
	 * 
	 * @param sDate:日期
	 * @param days:-1表示前一天，+1表示后一天，依次类推
	 * @param sFormat:日期格式
	 * @return
	 */
	public static String addDate(String sDate, int iDays, String sFormat) {
		String sNewDate = "";
		try {
			Date dteDate = stringToDate(sDate);
			if (dteDate == null)
				return "";
			long lNewTime = (dteDate.getTime() / 1000) + iDays * 60 * 60 * 24;// -1表示前一天，+1表示后一天，依次类推
			dteDate.setTime(lNewTime * 1000);
			sNewDate = dateToString(dteDate, sFormat);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sNewDate;
	}

	/**
	 * 增加日期
	 * 
	 * @param sDate:日期
	 * @param days:-1表示前一天，+1表示后一天，依次类推
	 * @return
	 */
	public static String addDate(String sDate, int iDays) {
		return addDate(sDate, iDays, "yyyy-MM-dd HH:mm:ss");
	}

	/**
	 * 增加秒
	 * 
	 * @param sData
	 * @param iSecond
	 * @return
	 */
	public static String addTime(String sData, int iSecond) {
		Calendar c = Calendar.getInstance();
		c.setTime(new Date()); // 设置当前日期
		c.add(Calendar.SECOND, iSecond); // 日期分钟加1,Calendar.DATE(天),Calendar.HOUR(小时)
		Date date = c.getTime(); // 结果
		return dateToString(date, "yyyy-MM-dd HH:mm:ss");
	}

	/**
	 * 获取IP
	 * 
	 * @param htpRequest
	 * @return
	 */
	public static String getIp(HttpServletRequest htpRequest) {
		String sIp = "";
		try {
			if (htpRequest != null) {
				sIp = htpRequest.getRemoteAddr();
			}
			if ("127.0.0.1".equals(sIp)) {
				sIp = InetAddress.getLocalHost().getHostAddress();
			}
		} catch (Exception e) {
		}
		return sIp;
	}

	/**
	 * 可为空值，通过程序判断后，dao会自动换为空值（DAO中更新方法专用）
	 * 
	 * @param sValue
	 * @return
	 */
	public static String canNullValue(String sValue) {
		return clearNull(sValue, UPDATE_STRING_NULL_VALUE);
	}

	public static Long canNullValueLong(Long lValue) {
		return lValue == null ? UPDATE_LONG_NULL_VALUE : lValue;
	}

	public static Integer canNullValueInteger(Integer iValue) {
		return iValue == null ? UPDATE_INTEGER_NULL_VALUE : iValue;
	}

	public static Double canNullValueDouble(Double dValue) {
		return dValue == null ? UPDATE_DOUBLE_NULL_VALUE : dValue;
	}

	public static Float canNullValueFloat(Float fValue) {
		return fValue == null ? UPDATE_FLOAT_NULL_VALUE : fValue;
	}

	/**
	 * 获取密码强度（0~20分：弱，21~30分：中，31~50分：强）
	 * 
	 * @param sPassword
	 * @return
	 */
	public static int getPasswordStrength(String sPassword) {
		int iStrength = 0;
		String[] sRegexArr = { "[0-9]", "[a-z]", "[A-Z]", "[\\W_]" };
		int iRepeatCount = 0;
		String sPrevChar = "";
		try {
			// 检查长度
			int iLength = sPassword.length();
			iStrength += iLength > 18 ? 18 : iLength;
			// 检查类型
			for (int i = 0; i < sRegexArr.length; i++) {
				if (getPatternMatch(sPassword, sRegexArr[i]).length() > 0) {
					iStrength += 4;
				}
			}
			// 强度分数
			for (int i = 0; i < sRegexArr.length; i++) {
				if (getPatternMatch(sPassword, sRegexArr[i]).length() >= 2) {
					iStrength += 2;
				}
				if (getPatternMatch(sPassword, sRegexArr[i]).length() >= 5) {
					iStrength += 2;
				}
			}
			// 扣减分数
			for (int i = 0; i < sPassword.length(); i++) {
				if (sPrevChar.equals(String.valueOf(sPassword.charAt(i)))) {
					iRepeatCount += 1;
				} else {
					sPrevChar = String.valueOf(sPassword.charAt(i));
				}
			}
			iStrength -= (iRepeatCount * 1);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return iStrength;
	}

	/**
	 * 获取正则表达式匹配结果
	 * 
	 * @param sContent要匹配的内容
	 * @param sPattern正则表达式
	 * @return
	 */
	public static boolean getPatternResult(String sContent, String sPattern) {
		try {
			Pattern pattern = Pattern.compile(sPattern);
			Matcher matcher = pattern.matcher(sContent);
			return matcher.matches();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	/**
	 * 获取性别（身份证）
	 * 
	 * @param sIdCard
	 * @return
	 */
	public static String getGenderByIdCard(String sIdCard) {
		String sGender = "";
		if (sIdCard != null && sIdCard.length() == 15) {// 15位身份证号码
			if (Integer.valueOf(sIdCard.charAt(14) / 2) * 2 != sIdCard.charAt(14)) {
				sGender = "1";
			} else {
				sGender = "2";
			}
		} else if (sIdCard != null && sIdCard.length() == 18) {// 18位身份证号码
			if (Integer.valueOf(sIdCard.charAt(16) / 2) * 2 != sIdCard.charAt(16)) {
				sGender = "1";
			} else {
				sGender = "2";
			}
		}
		return sGender;
	}

	/**
	 * 获取出生日期（身份证）
	 * 
	 * @param sIdCard
	 * @return
	 */
	public static String getBirthdayByIdCard(String sIdCard) {
		String sBirthday = "";
		if (CommonBean.checkIdCard(sIdCard)) {
			if (sIdCard != null && sIdCard.length() == 15) {// 15位身份证号码
				sBirthday = "" + sIdCard.charAt(6) + sIdCard.charAt(7);
				if (Integer.valueOf(sBirthday) < 10) {
					sBirthday = "20" + sBirthday;
				} else {
					sBirthday = "19" + sBirthday;
				}
				sBirthday = sBirthday + "-" + sIdCard.charAt(8) + sIdCard.charAt(9);// yyyy-MM
				sBirthday += "-" + sIdCard.charAt(10) + sIdCard.charAt(11);// -dd
			} else if (sIdCard != null && sIdCard.length() == 18) {// 18位身份证号码
				sBirthday = "" + sIdCard.charAt(6) + sIdCard.charAt(7) + sIdCard.charAt(8) + sIdCard.charAt(9);// yyyy
				sBirthday += "-" + sIdCard.charAt(10) + sIdCard.charAt(11);// -MM
				sBirthday += "-" + sIdCard.charAt(12) + sIdCard.charAt(13);// -dd
			}
		}
		return sBirthday;
	}

	/**
	 * 是否邮箱
	 * 
	 * @param sEmail
	 * @return
	 */
	public static boolean isEmail(String sEmail) {
		try {
			// 合法E-mail地址：
			// 1. 必须包含一个并且只有一个符号“@”
			// 2. 第一个字符不得是“@”或者“.”
			// 3. 不允许出现“@.”或者.@
			// 4. 结尾不得是字符“@”或者“.”
			// 5. 允许“@”前的字符中出现“＋”
			// 6. 不允许“＋”在最前面，或者“＋@”
			Pattern p = Pattern
					.compile("^([a-z0-9A-Z]+[-|\\.|_]?)+[a-z0-9A-Z_]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");
			Matcher m = p.matcher(sEmail);
			return m.matches();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	/**
	 * 是否手机号码
	 * 
	 * @param sNumber
	 * @return
	 */
	public static boolean isMobileNumber(String sNumber) {
		try {
			// 移动：134、135、136、137、138、139、150、151、157(TD)、158、159、183、187、188
			// 联通：130、131、132、152、155、156、185、186、14x
			// 电信：133、153、180、189、（1349卫通）
			/*
			 * if("184".equals(sNumber.substring(0,3))){//184号码，非法 return false;
			 * }
			 */
			Pattern p = Pattern.compile("^((13[0-9]{1})|(14[0-9]{1})|(15[^4,\\D]{1})|(18[^4,\\D]{1}))\\d{8}$");
			Matcher m = p.matcher(sNumber);
			return m.matches();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	/**
	 * 改变html的符号
	 * 
	 * @param sHtml
	 * @return
	 */
	public static String changeHtmlSymbol(String sHtml) {
		if (sHtml == null || "".equals(sHtml))
			return "";
		sHtml = sHtml.replace("<", "&lt;");
		sHtml = sHtml.replace(">", "&gt;");
		sHtml = sHtml.replace("\"", "&quot;");
		return sHtml;
	}

	/**
	 * 判断是否Windows操作系统
	 * 
	 * @return
	 */
	public static boolean isWindowsOS() {
		boolean bWindowsOS = false;
		String sOsName = System.getProperty("os.name");
		if (sOsName != null && sOsName.toLowerCase().indexOf("windows") > -1) {
			bWindowsOS = true;
		}
		return bWindowsOS;
	}

	/**
	 * 获取配置文件的值(String)
	 * 
	 * @return
	 */
	public static String getProStrValue(PropertyUtils puProperty, String sPropertyName) {
		String sValue = "";
		try {
			if (puProperty != null && puProperty.size() > 0) {
				sValue = puProperty.getProperty(sPropertyName, "");
			}
		} catch (Exception e) {
			System.out.println("读取配置文件出错！");
			e.printStackTrace();
		}
		return sValue;
	}

	/**
	 * 获取配置文件的值(int)
	 * 
	 * @return
	 */
	public static int getProIntValue(PropertyUtils puProperty, String sPropertyName) {
		int iValue = 0;
		try {
			if (puProperty != null && puProperty.size() > 0) {
				iValue = stringToInteger(puProperty.getProperty(sPropertyName, ""));
			}
		} catch (Exception e) {
			System.out.println("读取配置文件出错！");
			e.printStackTrace();
		}
		return iValue;
	}

	/**
	 * 加载配置文件
	 * 
	 * @param sPath配置文件的路径
	 * @return
	 */
	public static PropertyUtils loadProperty(String sPath) {
		try {
			PropertyUtils puConfig = new PropertyUtils(PROJECT_CHARSET);
			// String sPath = getProjectPath() + "/WEB-INF/classes/" +
			// CONFIG_FILE_NAME;
			// System.out.println("配置文件位置=" + sPath);
			File file = new File(sPath);
			if (file.exists()) {
				FileInputStream fis = new FileInputStream(file);
				puConfig.load(fis);
				fis.close();
				fis = null;
			} else {
				System.out.println("配置文件不存在！");
			}
			file = null;
			return puConfig;
		} catch (Exception e) {
			System.out.println("读取配置文件出错！");
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 获取项目url
	 * 
	 * @param request
	 * @return
	 */
	public static String getProjectUrl(HttpServletRequest request) {
		String sPath = "../";
		try {
			sPath = request.getScheme();
			sPath += "://" + request.getServerName() + ":" + request.getServerPort();
			sPath += request.getContextPath();
			return sPath;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sPath;
	}

	/**
	 * 获取项目路径(例如：d:/folderPath/projectName，注意：最后是没有/的。)
	 * 
	 * @return
	 */
	public static String getProjectPath() {
		String sProjectPath = "";
		try {
			String sTempPath = CommonBean.class.getClassLoader().getResource("").getPath();
			if (sTempPath.length() > 0) {
				sTempPath = sTempPath.substring(1, sTempPath.length());
				if (sTempPath.indexOf("\\") > -1) {
					sTempPath = sTempPath.replace("\\", "/");
				}
			}
			File file = new File(sTempPath);
			if (file.exists()) {
				sProjectPath = file.getAbsolutePath();
				if (sProjectPath.indexOf("\\") > -1) {
					sProjectPath = sProjectPath.replace("\\", "/");
				}
			} else {
				sProjectPath = file.getPath();
				if (sProjectPath.indexOf("\\") > -1) {
					sProjectPath = sProjectPath.replace("\\", "/");
				}
				sProjectPath = "/" + sProjectPath;
			}
			try {
				sProjectPath = URLDecoder.decode(sProjectPath, PROJECT_CHARSET);
			} catch (UnsupportedEncodingException e) {
				System.out.println("获取项目路径时URL解码时程序出错！");
				e.printStackTrace();
			}
			if (sProjectPath.indexOf("/WEB-INF") > -1) {
				sProjectPath = sProjectPath.substring(0, sProjectPath.indexOf("/WEB-INF"));
			}
			if (sProjectPath.indexOf("/buildClass") > -1) {
				sProjectPath = sProjectPath.substring(0, sProjectPath.indexOf("/buildClass")) + "/WebRoot";
			}
			if (sProjectPath.endsWith("/")) {
				sProjectPath = sProjectPath.substring(0, sProjectPath.length() - 1);
			}
			// System.out.println("项目路径=" + sProjectPath);
		} catch (Exception e) {
			System.out.println("获取项目路径时程序出错！");
			e.printStackTrace();
		}
		return sProjectPath;
	}

	/**
	 * 页面使用encodeURI，就要使用此方式将参数的编码转换
	 * 
	 * @param sValue
	 * @return
	 */
	public static String decode(String sValue) {
		sValue = clearNull(sValue, "");
		try {
			if (sValue != null && !"".equals(sValue)) {
				// sValue = new String(sValue.getBytes("ISO8859_1"),
				// PROJECT_CHARSET);
				sValue = URLDecoder.decode(sValue, PROJECT_CHARSET);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sValue;
	}

	/**
	 * 页面使用encodeURI，就要使用此方式将参数的编码转换
	 * 
	 * @param sValue
	 * @return
	 */
	public static String decode(String sValue, String sDefaultValue) {
		sValue = clearNull(sValue, sDefaultValue);
		try {
			if (sValue != null && !"".equals(sValue)) {
				sValue = URLDecoder.decode(sValue, PROJECT_CHARSET);
				// sValue = new String(sValue.getBytes("ISO8859_1"),
				// PROJECT_CHARSET);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sValue;
	}

	/**
	 * 获取范围条件
	 * 
	 * @param sRange范围
	 * @param sField字段
	 * @param sFieldType:字段类型（1-数值,2-字符串,3-时间,4-自带时间）
	 * @return
	 */
	public static String getRangeCondition(String sRange, String sField, String sFieldType) {
		sRange = clearNull(sRange);
		String sCondition = "", sMinValue = "", sMaxValue = "";
		if (sRange.indexOf("~") > -1) {
			String[] sRangeArr = sRange.split("~");
			if (sRange.endsWith("~") && sRange.length() > 1 && sRangeArr.length == 1) {
				if ("3".equals(sFieldType) || "4".equals(sFieldType)) {
					sMinValue = CommonBean.clearNull(sRangeArr[0]);
				} else {
					sMinValue = CommonBean.stringToInteger(CommonBean.clearNull(sRangeArr[0])).toString();
				}
			} else if (sRange.startsWith("~") && sRange.length() > 1 && sRangeArr.length == 2) {
				if ("3".equals(sFieldType) || "4".equals(sFieldType)) {
					sMaxValue = CommonBean.clearNull(sRangeArr[1]);
				} else {
					sMaxValue = CommonBean.stringToInteger(CommonBean.clearNull(sRangeArr[1])).toString();
				}
			} else if (sRange.length() > 1 && sRangeArr.length == 2) {
				sMinValue = CommonBean.clearNull(sRangeArr[0]);
				sMaxValue = CommonBean.clearNull(sRangeArr[1]);
			}
			if (!"".equals(sMinValue)) {
				if ("1".equals(sFieldType)) {
					sCondition += " and " + sField + " >= " + sMinValue + " ";
				} else if ("2".equals(sFieldType)) {
					sCondition += " and " + sField + " >= '" + sMinValue + "' ";
				} else if ("3".equals(sFieldType)) {
					sCondition += " and " + sField + " >= '" + sMinValue + " 00:00:00' ";
				} else if ("4".equals(sFieldType)) {
					sCondition += " and " + sField + " >= '" + sMinValue + "' ";
				}
			}
			if (!"".equals(sMaxValue)) {
				if ("1".equals(sFieldType)) {
					sCondition += " and " + sField + " <= " + sMaxValue + " ";
				} else if ("2".equals(sFieldType)) {
					sCondition += " and " + sField + " <= '" + sMaxValue + "' ";
				} else if ("3".equals(sFieldType)) {
					sCondition += " and " + sField + " <= '" + sMaxValue + " 23:59:59' ";
				} else if ("4".equals(sFieldType)) {
					sCondition += " and " + sField + " <= '" + sMaxValue + "' ";
				}
			}
		}
		// System.out.println("sCondition=" + sCondition);
		return sCondition;
	}

	/**
	 * 获取日期范围条件
	 * 
	 * @param sAgeRange
	 * @return
	 */
	public static String getAgeRangeCondition(String sAgeRange) {
		sAgeRange = clearNull(sAgeRange);
		String sCondition = "", sMinValue = "", sMaxValue = "";
		if (sAgeRange.indexOf("~") > -1) {
			String[] sAgeArr = sAgeRange.split("~");
			if (sAgeRange.endsWith("~") && sAgeRange.length() > 1 && sAgeArr.length == 1) {
				sMinValue = CommonBean.clearNull(sAgeArr[0]);
			} else if (sAgeRange.startsWith("~") && sAgeRange.length() > 1 && sAgeArr.length == 2) {
				sMaxValue = CommonBean.clearNull(sAgeArr[1]);
			} else if (sAgeRange.length() > 1 && sAgeArr.length == 2) {
				sMinValue = CommonBean.clearNull(sAgeArr[0]);
				sMaxValue = CommonBean.clearNull(sAgeArr[1]);
			}
			int iNowYear = CommonBean.stringToInteger(CommonBean.getNowTime("yyyy"));
			int iMinYear = 0, iMaxYear = 0;
			if (!"".equals(sMinValue)) {
				iMinYear = iNowYear - CommonBean.stringToInteger(sMinValue);
				sMinValue = iMinYear + "-12-31";
			} else {
				sMinValue = "";
			}
			if (!"".equals(sMaxValue)) {
				iMaxYear = iNowYear - CommonBean.stringToInteger(sMaxValue);
				sMaxValue = iMaxYear + "-01-01";
			} else {
				sMaxValue = "";
			}
			if (!"".equals(sMinValue)) {
				sCondition += " and target_birthday <= '" + sMinValue + "' ";
			}
			if (!"".equals(sMaxValue)) {
				sCondition += " and target_birthday >= '" + sMaxValue + "' ";
			}
		}
		// System.out.println("sCondition=" + sCondition);
		return sCondition;
	}

	/**
	 * 获取日期范围条件(按实岁计算)
	 * 
	 * @param sAgeRange
	 * @return
	 */
	public static String getAgeRangeCondition(String sAgeRange, String sFieldName) {
		sAgeRange = clearNull(sAgeRange);
		String sCondition = "", sMinValue = "", sMaxValue = "";
		if (sAgeRange.indexOf("~") > -1) {
			String[] sAgeArr = sAgeRange.split("~");
			if (sAgeRange.endsWith("~") && sAgeRange.length() > 1 && sAgeArr.length == 1) {
				sMinValue = CommonBean.clearNull(sAgeArr[0]);
			} else if (sAgeRange.startsWith("~") && sAgeRange.length() > 1 && sAgeArr.length == 2) {
				sMaxValue = CommonBean.clearNull(sAgeArr[1]);
			} else if (sAgeRange.length() > 1 && sAgeArr.length == 2) {
				sMinValue = CommonBean.clearNull(sAgeArr[0]);
				sMaxValue = CommonBean.clearNull(sAgeArr[1]);
			}
			int iNowYear = CommonBean.stringToInteger(CommonBean.getNowTime("yyyy"));
			int iMinYear = 0, iMaxYear = 0;
			String sNowDate = CommonBean.getNowTime().substring(0, 10);
			if (!"".equals(sMinValue)) {
				iMinYear = iNowYear - CommonBean.stringToInteger(sMinValue);
				sMinValue = iMinYear + "-" + sNowDate.substring(5, 10);// "-12-31";
			} else {
				sMinValue = "";
			}
			if (!"".equals(sMaxValue)) {
				iMaxYear = iNowYear - CommonBean.stringToInteger(sMaxValue) - 1;
				sMaxValue = iMaxYear + "-" + CommonBean.addDate(sNowDate, 1).substring(5, 10);// "-01-01";
			} else {
				sMaxValue = "";
			}
			if (!"".equals(sMinValue)) {
				sCondition += " and " + sFieldName + " <= '" + sMinValue + "'" + "and " + sFieldName + " != 'NULL' and "
						+ sFieldName + " != ''";
			}
			if (!"".equals(sMaxValue)) {
				sCondition += " and " + sFieldName + " >= '" + sMaxValue + "' ";
			}
		}
		// System.out.println("sCondition=" + sCondition);
		return sCondition;
	}

	/**
	 * 获取日期范围条件
	 * 
	 * @param sType:1-带“月日”判断;2-不带“月日”
	 * @return
	 */
	public static String getAgeRangeCondition(String sAgeRange, String sFieldName, String sType) {
		sAgeRange = clearNull(sAgeRange);
		String sCondition = "", sMinValue = "", sMaxValue = "";
		if (sAgeRange.indexOf("~") > -1) {
			String[] sAgeArr = sAgeRange.split("~");
			if (sAgeRange.endsWith("~") && sAgeRange.length() > 1 && sAgeArr.length == 1) {
				sMinValue = CommonBean.clearNull(sAgeArr[0]);
			} else if (sAgeRange.startsWith("~") && sAgeRange.length() > 1 && sAgeArr.length == 2) {
				sMaxValue = CommonBean.clearNull(sAgeArr[1]);
			} else if (sAgeRange.length() > 1 && sAgeArr.length == 2) {
				sMinValue = CommonBean.clearNull(sAgeArr[0]);
				sMaxValue = CommonBean.clearNull(sAgeArr[1]);
			}
			int iNowYear = CommonBean.stringToInteger(CommonBean.getNowTime("yyyy"));
			int iMinYear = 0, iMaxYear = 0;
			if (!"".equals(sMinValue)) {
				iMinYear = iNowYear - CommonBean.stringToInteger(sMinValue);
				if ("1".equals(sType)) {
					sMinValue = iMinYear + "-12-31";
				} else if ("2".equals(sType)) {//
					sMinValue = CommonBean.integerToString(iMinYear);
				}
			} else {
				sMinValue = "";
			}
			if (!"".equals(sMaxValue)) {
				iMaxYear = iNowYear - CommonBean.stringToInteger(sMaxValue);
				if ("1".equals(sType)) {
					sMaxValue = iMaxYear + "-01-01";
				} else if ("2".equals(sType)) {//
					sMaxValue = CommonBean.integerToString(iMaxYear);
				}

			} else {
				sMaxValue = "";
			}
			if (!"".equals(sMinValue)) {
				sCondition += " and " + sFieldName + " <= '" + sMinValue + "' ";
			}
			if (!"".equals(sMaxValue)) {
				sCondition += " and " + sFieldName + " >= '" + sMaxValue + "' ";
			}
		}
		// System.out.println("sCondition=" + sCondition);
		return sCondition;
	}

	/**
	 * 获取内部编号(时间16位+4位随机码)
	 */
	public static String getInnerNumber() {
		return getInnerNumber(20);
	}

	/**
	 * 获取内部编号(按长度生成)
	 */
	public static String getInnerNumber(int iLength) {
		String sNum = "";
		try {
			Date now = new Date();
			SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssMs");
			sNum = formatter.format(now);
			if (sNum.length() < 16) {
				for (int i = sNum.length(); i < 16; i++) {
					sNum += "0";
				}
			} else if (sNum.length() > 16) {
				sNum = sNum.substring(0, 16);
			}
			// sNum += getRandomNumber(iLength - 16);
			sNum = (sNum.length() > iLength) ? sNum.substring(0, iLength) : sNum + getRandomNumber(iLength - 16);
			// 如果循环插入时，间隔20毫秒就不会出现内部编号重复
			Thread.sleep(20);
			if (sNum.length() > iLength) {
				sNum = sNum.substring(0, iLength);
			}
		} catch (Exception e) {
		}
		return sNum;
	}

	/**
	 * 获取随机数
	 * 
	 * @param length
	 * @return
	 */
	public static String getRandomNumber(int length) {
		String sStr = "";
		try {
			if (length < 1) {
				return sStr;
			}
			int iBeginNum = 1;// 从1开始
			long iEndNum = (long) Math.pow(10, length);
			long iRanNum = 0;
			iRanNum = (long) (Math.random() * (iEndNum - iBeginNum) + iBeginNum);
			sStr = String.valueOf(iRanNum);
			if (sStr.length() < length) {// 不够位数，就在左边补零
				sStr = buildNumber(sStr, length);
			} else if (sStr.length() > length) {
				sStr = sStr.substring(0, length);// 防止超出长度
			}
		} catch (Exception e) {
			e.printStackTrace();
			// 异常就用0来代替
			sStr = buildNumber("0", length);
		}
		return sStr;
	}

	/**
	 * 为编号填充0
	 * 
	 * @param number
	 * @param digit
	 * @return
	 */
	public static String buildNumber(String number, int digit) {
		String tnum = "", tZero = "";
		int length = number.length();
		if (length <= 0 || length >= digit) {
			return number;
		}
		length = digit - length;
		for (int i = 0; i < length; i++) {
			tZero += "0";
		}
		tnum = tZero + number;
		return tnum;
	}

	/**
	 * 为编号填充0到右边
	 * 
	 * @param number
	 * @param digit
	 * @return
	 */
	public static String buildRightNumber(String number, int digit) {
		String tnum = "", tZero = "";
		int length = number.length();
		if (length <= 0 || length >= digit) {
			return number;
		}
		length = digit - length;
		for (int i = 0; i < length; i++) {
			tZero += "0";
		}
		tnum = number + tZero;
		return tnum;
	}

	/**
	 * 清除null
	 * 
	 * @param s
	 * @return
	 */
	public static String clearNull(String s) {
		return (s == null || s.length() < 1 || "null".equals(s) || "UPDATE_STRING_NULL_VALUE".equals(s)) ? "" : s;
	}

	/**
	 * 清除null
	 * 
	 * @param s
	 * @param def
	 * @return
	 */
	public static String clearNull(String s, String def) {
		return (s == null || s.length() < 1 || "null".equals(s)) ? def : s;
	}

	public Long clearNull(Long obj, Long def) {
		return (obj == null) ? def : obj;
	}

	public Long clearNull(Long obj) {
		return (obj == null) ? 0l : obj;
	}

	/**
	 * 获取当前时间
	 * 
	 * @return
	 */
	public static String getNowTime() {
		return getNowTime("yyyy-MM-dd HH:mm:ss");
	}

	/**
	 * 获取当前时间
	 * 
	 * @param format
	 * @return
	 */
	public static String getNowTime(String format) {
		SimpleDateFormat formatter = new SimpleDateFormat(format);
		Date date = new Date();
		String sDate = formatter.format(date);
		return sDate;
	}

	/**
	 * 是否日期格式
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isDateFormat(String str) {
		if (str == null) {
			return false;
		}
		String sEx = "^(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-";
		sEx += "(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))";
		sEx += "|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|";
		sEx += "((0[48]|[2468][048]|[3579][26])00))-02-29)$";
		if (str.length() == 10) {
			// Pattern code_p = Pattern.compile("\\d{4}\\-\\d{2}\\-\\d{2}");
			Pattern code_p = Pattern.compile(sEx);
			Matcher code_m = code_p.matcher(str);
			return code_m.find();
		} else if (str.length() == 4) {
			sEx = "^([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})$";
			Pattern code_p = Pattern.compile(sEx);
			Matcher code_m = code_p.matcher(str);
			return code_m.find();
		} else if (str.length() == 5) {
			sEx = "^([0-1]\\d|2[0-3]):[0-5]\\d$";
			Pattern code_p = Pattern.compile(sEx);
			Matcher code_m = code_p.matcher(str);
			return code_m.find();
		} else if (str.length() == 8) {
			sEx = "^([0-1]\\d|2[0-3]):[0-5]\\d:[0-5]\\d$";
			Pattern code_p = Pattern.compile(sEx);
			Matcher code_m = code_p.matcher(str);
			return code_m.find();
		} else {
			return false;
		}
	}

	/**
	 * 是否IP格式
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isIpFormat(String str) {
		if (str == null) {
			return false;
		}
		String sEx = "^((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)$";
		Pattern code_p = Pattern.compile(sEx);
		Matcher code_m = code_p.matcher(str);
		return code_m.find();
	}

	/**
	 * 是否端口格式
	 * 
	 * @param str
	 * @return
	 */
	public static boolean isPortFormat(String str) {
		if (str == null) {
			return false;
		}
		String sEx = "^([0-9]{1,4}|[1-5][0-9]{4}|6[0-5]{2}[0-3][0-5])$";// 0~65535
		Pattern code_p = Pattern.compile(sEx);
		Matcher code_m = code_p.matcher(str);
		return code_m.find();
	}

	/**
	 * 数组转String
	 * 
	 * @param array
	 * @param symbol
	 * @return
	 */
	public static String arrayToString(String[] array, String symbol) {
		String sStr = "";
		if (array != null && array.length > 0) {
			for (int i = 0; i < array.length; i++) {
				if (i == 0) {
					sStr += array[i];
				} else {
					sStr += symbol + array[i];
				}
			}
		}
		return sStr;
	}

	/**
	 * List转String
	 * 
	 * @param array
	 * @param symbol
	 * @return
	 */
	public static String arrayListToString(List<?> array, String symbol) {
		String sStr = "";
		if (array != null && array.size() > 0) {
			for (int i = 0; i < array.size(); i++) {
				if (i == 0) {
					sStr += array.get(i);
				} else {
					sStr += symbol + array.get(i);
				}
			}
		}
		return sStr;
	}

	/**
	 * 字符串转数组
	 * 
	 * @param str
	 * @param symbol
	 * @return
	 */
	public static String[] stringToArray(String str, String symbol) {
		String[] sStr = {};
		if (str != null && str.indexOf(symbol) != -1) {
			sStr = str.split(symbol);
			if (sStr == null) {
				sStr = new String[] {};
			}
		} else if (str != null && str.length() > 0) {
			sStr = new String[] { str };
		}
		return sStr;
	}

	/**
	 * @param date
	 * @return
	 */
	public static String dateToString(java.sql.Date date) {
		String sDate = "";
		if (date != null) {
			try {
				String format = "";
				if (date.toString().length() == 10) {
					format = "yyyy-MM-dd";
				} else if (date.toString().length() == 19
						|| (date.toString().length() > 19 && date.toString().indexOf(".") > -1)) {
					format = "yyyy-MM-dd HH:mm:ss";
				} else if (date.toString().length() == 16) {
					format = "yyyy-MM-dd HH:mm";
				} else if (date.toString().length() == 5) {
					format = "HH:mm";
				}
				sDate = dateToString(date, format);
			} catch (Exception e) {

			}
		}
		return sDate;
	}

	public static String dateToString(Date date) {
		String sDate = "";
		if (date != null) {
			try {
				String format = "";
				if (date.toString().length() == 10) {
					format = "yyyy-MM-dd";
				} else if (date.toString().length() == 19
						|| (date.toString().length() > 19 && date.toString().indexOf(".") > -1)) {
					format = "yyyy-MM-dd HH:mm:ss";
				} else if (date.toString().length() == 16) {
					format = "yyyy-MM-dd HH:mm";
				} else if (date.toString().length() == 5) {
					format = "HH:mm";
				}
				sDate = dateToString(date, format);
			} catch (Exception e) {

			}
		}
		return sDate;
	}

	/**
	 * 日期转换为字符
	 * 
	 * @param date
	 * @param format
	 * @return
	 */
	public static String dateToString(java.sql.Date date, String format) {
		String sDate = "";
		format = clearNull(format, "yyyy-MM-dd");
		if (date != null) {
			try {
				SimpleDateFormat format1 = new SimpleDateFormat(format);
				sDate = format1.format(date);
			} catch (Exception e) {

			}
		}
		return sDate;
	}

	public static String dateToString(Date date, String format) {
		String sDate = "";
		format = clearNull(format, "yyyy-MM-dd");
		if (date != null) {
			try {
				SimpleDateFormat format1 = new SimpleDateFormat(format);
				sDate = format1.format(date);
			} catch (Exception e) {

			}
		}
		return sDate;
	}

	public static Integer stringToInteger(String num) {
		Integer iNum = 0;
		if (num != null || !"".equals(num)) {
			try {
				iNum = Integer.valueOf(num);
			} catch (Exception e) {
				iNum = 0;
			}
		}
		return iNum;
	}

	public static int IntegerToint(Integer num) {
		int iNum = 0;
		if (num != null) {
			try {
				iNum = num.intValue();
			} catch (Exception e) {

			}
		}
		return iNum;
	}

	public static String integerToString(Integer num) {
		String sNum = "0";
		if (num != null) {
			try {
				sNum = num.intValue() + "";
			} catch (Exception e) {

			}
		}
		return sNum;
	}

	public static String doubleToString(Double doub) {
		String sDate = "0.00";
		if (doub != null) {
			try {
				DecimalFormat format = new java.text.DecimalFormat("##0.00");
				sDate = format.format(doub);
			} catch (Exception e) {

			}
		}
		return sDate;
	}

	public static String doubleToString(Double doub, String sFormat) {
		String sDate = "0.00";
		if (doub != null) {
			try {
				if (sFormat == null || "".equals(sFormat))
					sFormat = "##0.00";
				DecimalFormat format = new java.text.DecimalFormat(sFormat);
				sDate = format.format(doub);
			} catch (Exception e) {

			}
		}
		return sDate;
	}

	public static String bigDecimalToString(BigDecimal decimal) {
		return doubleToString(decimal.doubleValue());
	}

	public static String bigDecimalToString(BigDecimal decimal, String sFormat) {
		return doubleToString(decimal.doubleValue(), sFormat);
	}

	public static String floatToString(Float floa) {
		String sDate = "0.00";
		if (floa != null) {
			try {
				DecimalFormat format = new java.text.DecimalFormat("##0.00");
				sDate = format.format(floa);
			} catch (Exception e) {

			}
		}
		return sDate;
	}

	public static String doubleToPercent(Double value) {
		return doubleToPercent(value, 2);
	}

	public static String doubleToPercent(Double value, int fraction) {
		value = (value == null) ? 0d : value;
		String sResult = "0.00%";
		try {
			NumberFormat format = NumberFormat.getPercentInstance();
			format.setMaximumFractionDigits(fraction);
			sResult = format.format(value);
		} catch (Exception e) {

		}
		return sResult;
	}

	public static String bigDecimalToPercent(BigDecimal value) {
		return bigDecimalToPercent(value, 2);
	}

	public static String bigDecimalToPercent(BigDecimal value, int fraction) {
		if (value == null) {
			return "0.00%";
		} else {
			return doubleToPercent(value.doubleValue(), fraction);
		}
	}

	public static Double stringToDouble(String sNum) {
		if ("".equals(clearNull(sNum))) {
			return 0d;
		}
		Double lNum = 0d;
		try {
			// lNum = Double.parseDouble(sNum);
			lNum = changeDouble(sNum, 2);
		} catch (Exception e) {
			// System.out.println("Double转型异常！");
		}
		return lNum;
	}

	// 四舍五入函数，参数1：数值，参数2：要保留的小数位数
	public static Double changeDouble(String sNum, int num) {
		if (num < 0)
			return null;
		int k = 1;
		double tempNum = 0.0D;
		try {
			for (int i = 0; i < num; i++) {
				k = k * 10;
			}
			double a = Double.parseDouble(sNum);
			tempNum = (double) Math.round(a * k) / k;
		} catch (Exception e) {

		}
		return tempNum;
	}

	// 四舍五入函数，参数1：数值，参数2：要保留的小数位数
	public static Double changeDouble(double dNum, int num) {
		if (num < 0)
			return null;
		int k = 1;
		double tempNum = 0.0D;
		try {
			for (int i = 0; i < num; i++) {
				k = k * 10;
			}
			tempNum = (double) Math.round(dNum * k) / k;
		} catch (Exception e) {

		}
		return tempNum;
	}

	public static Long stringToLong(String sNum) {
		if ("".equals(clearNull(sNum))) {
			return null;
		}
		Long lNum = null;
		try {
			lNum = Long.parseLong(sNum);
		} catch (Exception e) {
			// System.out.println("Long转型异常！");
		}
		return lNum;
	}

	public static String longToString(Long lon) {
		String sDate = "";
		if (lon != null) {
			try {
				sDate = lon.toString();
			} catch (Exception e) {

			}
		}
		return sDate;
	}

	/**
	 * 长整型转换为浮点型
	 * 
	 * @param lon
	 * @return
	 */
	public static long LongTolong(Long lon) {
		long lData = 0;
		if (lon != null) {
			try {
				lData = lon.longValue();
			} catch (Exception e) {
			}
		}
		return lData;
	}

	// string日期形转为date形
	public static Date stringToDate(String sDate) {
		// DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd"); yyyyMMddHHmm
		// DateFormat format2= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		if ("".equals(clearNull(sDate))) {
			return null;
		}
		Date date = null;
		try {
			SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
			SimpleDateFormat format2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			SimpleDateFormat format3 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
			SimpleDateFormat format4 = new SimpleDateFormat("HH:mm");
			SimpleDateFormat format5 = new SimpleDateFormat("yyyy年M月d日H时m分");
			SimpleDateFormat format6 = new SimpleDateFormat("yyyy/M/d HH:m:s");
			SimpleDateFormat format7 = new SimpleDateFormat("yyyyMMddHHmm");
			if (sDate.length() == 10) {
				date = format1.parse(sDate);
			} else if (sDate.length() == 19 || (sDate.length() > 19 && sDate.indexOf(".") > -1)) {
				date = format2.parse(sDate);
			} else if (sDate.length() == 16 && sDate.indexOf("/") < 0) {
				date = format3.parse(sDate);
			} else if (sDate.length() == 5) {
				date = format4.parse(sDate);
			} else if (sDate.indexOf("年") > -1) {
				date = format5.parse(sDate);
			} else if (sDate.indexOf("/") > -1) {
				date = format6.parse(sDate);
			} else if (sDate.length() == 12) {
				date = format7.parse(sDate);
			}
		} catch (ParseException e) {
			System.out.println("日期转型异常！");
		}
		return date;
	}

	public static String objectToString(Object obj) {
		String sStr = "";
		if (obj == null) {
			return sStr;
		}
		if (obj instanceof String) {
			sStr = obj.toString();
		} else if (obj instanceof Integer) {
			sStr = clearNull(obj.toString());
		} else if (obj instanceof Double) {
			sStr = doubleToString(stringToDouble(obj.toString()));
		} else if (obj instanceof Long) {
			sStr = clearNull(obj.toString());
		} else if (obj instanceof Date) {
			Date date = stringToDate(obj.toString());
			sStr = dateToString(date);
		} else if (obj instanceof BigDecimal) {
			if (obj.toString().indexOf(".") > -1) {
				sStr = doubleToString(stringToDouble(obj.toString()));
			} else {
				sStr = longToString(stringToLong(obj.toString()));
			}
		}
		return sStr;
	}

	public static String objectToString(Object obj, String sType) {
		String sStr = "";
		if (obj == null) {
			return sStr;
		}
		if (obj instanceof BigDecimal) {
			BigDecimal big = (BigDecimal) obj;
			if ("1".equals(sType)) {
				sStr = integerToString(big.intValue());
			} else if ("2".equals(sType)) {
				sStr = longToString(big.longValue());
			} else if ("3".equals(sType)) {
				sStr = doubleToString(big.doubleValue());
			}
		} else if (obj instanceof Integer) {
			Integer big = (Integer) obj;
			sStr = integerToString(big);
		} else if (obj instanceof Long) {
			Long big = (Long) obj;
			sStr = longToString(big);
		} else if (obj instanceof Double) {
			Double big = (Double) obj;
			sStr = doubleToString(big);
		} else if (obj instanceof Float) {
			Float big = (Float) obj;
			sStr = floatToString(big);
		}
		return sStr;
	}

	public static Double objectToDouble(Object obj) {
		Double dNum = null;
		if (obj == null) {
			return dNum;
		}
		if (obj instanceof BigDecimal) {
			BigDecimal big = (BigDecimal) obj;
			dNum = big.doubleValue();
		} else if (obj instanceof Double) {
			dNum = ((Double) obj).doubleValue();
		} else if (obj instanceof Float || obj instanceof Long || obj instanceof Integer) {
			try {
				dNum = Double.parseDouble(obj.toString());
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return dNum;
	}

	public static Long objectToLong(Object obj) {
		Long lNum = null;
		if (obj == null) {
			return lNum;
		}
		if (obj.toString().indexOf(".") < 0) {
			lNum = stringToLong(obj.toString());
		}
		return lNum;
	}

	public static Integer objectToInteger(Object obj) {
		Integer iNum = null;
		if (obj == null) {
			return iNum;
		}
		if (obj.toString().indexOf(".") < 0) {
			iNum = stringToInteger(obj.toString());
		}
		return iNum;
	}

	public static BigDecimal objectToBigDecimal(Object obj) {
		if (obj == null) {
			return null;
		}
		if (obj instanceof BigDecimal) {
			return (BigDecimal) obj;
		} else if (obj instanceof Double) {
			return new BigDecimal((Double) obj);
		} else if (obj instanceof Float) {
			return new BigDecimal((Float) obj);
		} else if (obj instanceof Long) {
			return new BigDecimal((Long) obj);
		} else if (obj instanceof Integer) {
			return new BigDecimal((Integer) obj);
		} else if (obj instanceof Short) {
			return new BigDecimal((Short) obj);
		} else {
			return null;
		}
	}

	public static double DoubleTodouble(Double dNum) {
		double num = 0d;
		if (dNum == null) {
			return num;
		}
		// num = dNum.doubleValue();
		Double dTempNum = changeDouble(dNum, 2);
		if (dTempNum == null) {
			return num;
		}
		num = dTempNum.doubleValue();
		return num;
	}

	/**
	 * 清除非法字符
	 * 
	 * @param sStr
	 * @return
	 */
	public static String clearIllegalChar(String sStr) {
		if (sStr != null && sStr.length() > 0) {
			sStr = sStr.replace("\r\n", "");
			sStr = sStr.replace("\n", "");
		}
		return sStr;
	}

	/**
	 * 清除非法SQL字符
	 * 
	 * @param sStr
	 * @return
	 */
	public static String clearIllegalSqlChar(String sStr) {
		sStr = clearNull(sStr);
		if (sStr != null && sStr.length() > 0) {
			sStr = sStr.replace("\'", "\\'");
		}
		return sStr;
	}

	/**
	 * 检查数据库非法字符
	 * 
	 * @param sStr
	 *            数组
	 * @return true:不存在非法数据 false:存在非法数据
	 */
	public static boolean checkIllegalData(String sStr) {
		boolean flag = true;
		if (sStr == null || sStr.length() < 1) {
			return true;
		}
		try {
			// String sqlkey =
			// ":|;|\"|>|<|--|sp_|xp_||dir|cmd|^|+|$|'|copy|format|and|or|exec|insert|select|delete|update|count|%|chr|mid|master|truncate|char|declare";
			String sSqlKey = "sp_|xp_|insert into |delete from |update |truncate table |declare |drop database |drop table |--|/*|*/";
			StringTokenizer stk = new StringTokenizer(sSqlKey.toString(), "|");
			String sTempStk = "";
			while (stk.hasMoreTokens()) {
				sTempStk = stk.nextToken();
				if (sStr.toLowerCase().indexOf(sTempStk) != -1) {
					System.out.println("该字符串含有非法字符(" + sTempStk + ")=" + sStr);
					flag = false;
				}
			}
		} catch (Exception e) {
			System.out.println("检查数据库非法字符出错！");
			e.printStackTrace();
		}
		return flag;
	}

	public static String setCn(String str, String codename) {
		if (str == null) {
			str = "";
		}
		try {
			str = new String(str.getBytes("ISO8859-1"), codename);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			str = "";
		}
		return str;
	}

	public static String setCn(byte[] sbyte, String codename) {
		String str = "";
		if (sbyte == null) {
			return str;
		}
		try {
			codename = clearNull(codename, "GBK");
			str = new String(sbyte, codename);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
			str = "";
		}
		return str;
	}

	// /**
	// * 重新生成sql
	// * @param sSql
	// * @param sTest2
	// * @param sTest3
	// * @return
	// */
	// public static String reBuildSql(String sSql, String sTest1, String
	// sTest2, String sTest3) {
	// String sTempSql = "";
	// if (sSql == null) { return sTempSql; }
	// try {
	// sTempSql = sSql;
	// // 处理语句含有[]的情况，生成有条件的语句
	// String sSqlCon = getPatternMatch(sTempSql, "\\[([^\\]]+)\\]");
	// System.out.println("正则出来的条件=" + sSqlCon);
	// if (sSqlCon.length() > 0) {
	// String[] sSqlConArr = sSqlCon.split("\\|");
	// if (sSqlConArr != null && sSqlConArr.length > 0) {
	// String sFindType = "";
	// if (sTest1.length() > 0 && sTest2.length() > 0 && sTest3.length() > 0)
	// {// 找有?1、?2和?3的条件
	// sFindType = "1";
	// } else if (sTest1.length() < 1 && sTest2.length() > 0 && sTest3.length()
	// > 0) {// 找有?2和?3的条件
	// sFindType = "2";
	// } else if (sTest1.length() > 0) {// 找只有?1的条件
	// sFindType = "3";
	// } else {
	// return sTempSql;
	// }
	// for (int i = 0; i < sSqlConArr.length; i++) {
	// if ("1".equals(sFindType) && sSqlConArr[i] != null &&
	// sSqlConArr[i].indexOf("?1") > -1 && sSqlConArr[i].indexOf("?2") > -1 &&
	// sSqlConArr[i].indexOf("?3") > -1) {
	// // 找有?1、?2和?3的条件
	// System.out.println("找到的条件=" + sSqlConArr[i]);
	// sTempSql = sTempSql.replace(sSqlCon, sSqlConArr[i].replace("[",
	// "").replace("]", ""));
	// break;
	// } else if ("2".equals(sFindType) && sSqlConArr[i] != null &&
	// sSqlConArr[i].indexOf("?1") < 0 && sSqlConArr[i].indexOf("?2") > -1 &&
	// sSqlConArr[i].indexOf("?3") > -1) {
	// // 找有?2和?3的条件
	// System.out.println("找到的条件=" + sSqlConArr[i]);
	// sTempSql = sTempSql.replace(sSqlCon, sSqlConArr[i].replace("[",
	// "").replace("]", ""));
	// break;
	// } else if ("3".equals(sFindType) && sSqlConArr[i] != null &&
	// sSqlConArr[i].indexOf("?1") > -1 && sSqlConArr[i].indexOf("?2") < 0 &&
	// sSqlConArr[i].indexOf("?3") < 0) {
	// // 找只有?1的条件
	// System.out.println("找到的条件=" + sSqlConArr[i]);
	// sTempSql = sTempSql.replace(sSqlCon, sSqlConArr[i].replace("[",
	// "").replace("]", ""));
	// break;
	// }
	// }
	// }
	// }
	// // 代入条件值
	// if (sTempSql.indexOf("?1") > -1 && sTest1.length() > 0) {
	// sTempSql = sTempSql.replace("?1", "'" + sTest1 + "'");
	// }
	// if (sTempSql.indexOf("?2") > -1 && sTest2.length() > 0) {
	// sTempSql = sTempSql.replace("?2", "'" + sTest2 + "'");
	// }
	// if (sTempSql.indexOf("?3") > -1 && sTest3.length() > 0) {
	// sTempSql = sTempSql.replace("?3", "'" + sTest3 + "'");
	// }
	// // if (sSql.indexOf("?1") > -1 && sTest1.length() > 0) {
	// // sSql = sSql.replace("?1", "'" + sTest1 + "'");
	// // } else if (sSql.indexOf("?1") > -1) {
	// // String sTemp = sSql.toLowerCase();
	// // if (sTemp.indexOf("where") > -1) {
	// // sSql = sTemp.replace(sTemp.substring(sTemp.indexOf("where"),
	// sTemp.indexOf("?1") + 2), "where 1=1 ");
	// // }
	// // }
	// // if (sSql.indexOf("?2") > -1 && sTest2.length() > 0) {
	// // sSql = sSql.replace("?2", "'" + sTest2 + "'");
	// // } else if (sSql.indexOf("?2") > -1) {
	// // sSql = sSql.replace("?2", "''");
	// // }
	// // if (sSql.indexOf("?3") > -1 && sTest3.length() > 0) {
	// // sSql = sSql.replace("?3", "'" + sTest3 + "'");
	// // } else if (sSql.indexOf("?3") > -1) {
	// // sSql = sSql.replace("?3", "''");
	// // }
	// // sTempSql = sSql;
	// // sTempSql = sTempSql.replace(" where ", " WHERE ");
	// // sTempSql = sTempSql.replace(" and ", " AND ");
	// // String[] sArr = sTempSql.split("AND");
	// // if (sArr != null && sArr.length > 1 && sArr[1] != null) {
	// // sArr = sArr[1].split("AND");
	// // if (sArr != null && sArr.length > 0) {
	// // for (int i = 0; i < sArr.length; i++) {
	// // if (sArr[i] == null) {
	// // continue;
	// // }
	// // if ((sTest2.length() < 1 && sArr[i].indexOf("?2") > -1) ||
	// (sTest3.length() < 1 && sArr[i].indexOf("?3") > -1)) {
	// // sTempSql = sTempSql.replace("AND" + sArr[i], "");
	// // }
	// // }
	// // }
	// // } else {
	// // return sSql;
	// // }
	// } catch (Exception e) {
	// e.printStackTrace();
	// }
	// return sTempSql;
	// }

	/**
	 * 获取正则表达式匹配的内容
	 * 
	 * @param sContent
	 * @param sPattern
	 * @return
	 */
	public static String getPatternMatch(String sContent, String sPattern) {
		String sTempStr = "";
		try {
			Pattern pattern = Pattern.compile(sPattern);
			Matcher matcher = pattern.matcher(sContent);
			if (matcher.find()) {
				sTempStr = clearNull(matcher.group());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sTempStr;
	}

	/**
	 * 执行命令
	 * 
	 * @param sCommand：命令
	 * @param bGetInfo：是否获取执行结果
	 * @return
	 */
	public static String execCommand(String sCommand, boolean bGetInfo) {
		String sResult = "", sErrorResult = "";
		try {
			Runtime run = Runtime.getRuntime();
			System.out.println("bGetInfo=" + bGetInfo + ",sCommand=" + sCommand);
			if (bGetInfo) {
				Process process = run.exec(sCommand);
				BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
				BufferedReader error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
				String line = null;
				while ((line = input.readLine()) != null) {
					sResult += line + "\n";
				}
				String errorLine = null;
				while ((errorLine = error.readLine()) != null) {
					sErrorResult += errorLine + "\n";
				}
				System.out.println("sResult=" + sResult);
				System.out.println("sErrorResult=" + sErrorResult);
				if (sErrorResult != null && sErrorResult.startsWith("ERROR")) {
					sResult = sErrorResult;
				}
				input.close();
				error.close();
			} else {
				run.exec(sCommand);
			}
		} catch (Exception e) {
			e.printStackTrace();
			sResult = "";
		}
		return sResult;
	}

	/**
	 * 根据指定日期获取星期几
	 * 
	 * @param dayTime：指定日期,格式"yyyy-MM-dd"
	 * @return 返回数字1-星期一;2-星期二;3-星期三;4-星期四
	 */

	public static int dayForWeek(String dayTime) {
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		Calendar c = Calendar.getInstance();
		try {
			c.setTime(format.parse(dayTime));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		int dayForWeek = 0;
		if (c.get(Calendar.DAY_OF_WEEK) == 1) {
			dayForWeek = 7;
		} else {
			dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
		}
		return dayForWeek;
	}

	public static Date stringChangeToDate(String sDate) {
		String fmt = "yyyy-MM-dd HH:mm:ss";
		SimpleDateFormat sdf = new SimpleDateFormat(fmt);
		Date date = null;
		try {
			date = sdf.parse(sDate);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return date;
	}

	public static double getDiscrepantHoursForOneDay(Date dBeginDate, Date dEndDate) {
		double Hours = 0;
		try {
			if (dBeginDate == null || dEndDate == null) {
				return Hours;
			}
			dBeginDate = formatDate(dBeginDate, "yyyy-MM-dd HH:mm:ss");
			dEndDate = formatDate(dEndDate, "yyyy-MM-dd HH:mm:ss");

			Calendar bc = Calendar.getInstance();
			bc.setTime(dBeginDate);
			Calendar ec = Calendar.getInstance();
			ec.setTime(dEndDate);

			double totalMillis = ec.getTimeInMillis() - bc.getTimeInMillis();
			double oneDayMillis = 60 * 60 * 1000;
			double resultMillis = totalMillis / oneDayMillis;
			Hours = CommonBean.changeDouble(resultMillis, 1);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Hours;
	}

	public static long getDiscrepantSecond(Date dBeginDate, Date dEndDate) {
		long resultSecond = 0;
		try {
			if (dBeginDate == null || dEndDate == null) {
				return resultSecond;
			}
			dBeginDate = formatDate(dBeginDate, "yyyy-MM-dd HH:mm:ss");
			dEndDate = formatDate(dEndDate, "yyyy-MM-dd HH:mm:ss");

			long totalMillis = dEndDate.getTime() - dBeginDate.getTime();
			resultSecond = totalMillis / 1000;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultSecond;
	}

	/**
	 * 计算完成回复所用的时间、完成预约服务所用的时间
	 * 
	 * @param mvoSelect
	 * @return
	 */
	public static double getReplyOrCompleteConsumeTime(String startTime, String endTime) {
		double iConsumeHours = 0;
		// 若是同一日，则直接相减
		if (startTime.substring(0, 10).equals(endTime.substring(0, 10))) {
			double dDayHour = 0;
			if (endTime.substring(11).compareTo("12:00:00") < 0) {
				if (startTime.substring(11).compareTo("08:00:00") < 0) {
					String tempTime = startTime.substring(0, 10) + " " + "08:00:00";
					dDayHour = getDiscrepantHoursForOneDay(stringChangeToDate(tempTime), stringChangeToDate(endTime));
				} else {
					dDayHour = getDiscrepantHoursForOneDay(stringChangeToDate(startTime), stringChangeToDate(endTime));
				}
			} else if (endTime.substring(11).compareTo("12:00:00") > 0
					&& endTime.substring(11).compareTo("14:00:00") < 0) {
				if (startTime.substring(11).compareTo("08:00:00") < 0) {
					dDayHour = 4;
				} else {
					String tempTime = startTime.substring(0, 10) + " " + "12:00:00";
					dDayHour = getDiscrepantHoursForOneDay(stringChangeToDate(startTime), stringChangeToDate(tempTime));
				}
			} else if (endTime.substring(11).compareTo("14:00:00") > 0
					&& endTime.substring(11).compareTo("18:00:00") < 0) {
				if (startTime.substring(11).compareTo("08:00:00") < 0) {
					String tempTime = startTime.substring(0, 10) + " " + "08:00:00";
					dDayHour = getDiscrepantHoursForOneDay(stringChangeToDate(tempTime), stringChangeToDate(endTime))
							- 2;
				} else if (startTime.substring(11).compareTo("08:00:00") > 0
						&& startTime.substring(11).compareTo("12:00:00") < 0) {
					dDayHour = getDiscrepantHoursForOneDay(stringChangeToDate(startTime), stringChangeToDate(endTime))
							- 2;
				} else if (startTime.substring(11).compareTo("12:00:00") > 0
						&& startTime.substring(11).compareTo("14:00:00") < 0) {
					String tempTime = startTime.substring(0, 10) + " " + "14:00:00";
					dDayHour = getDiscrepantHoursForOneDay(stringChangeToDate(tempTime), stringChangeToDate(endTime));
				} else if (startTime.substring(11).compareTo("14:00:00") > 0
						&& startTime.substring(11).compareTo("18:00:00") < 0) {
					dDayHour = getDiscrepantHoursForOneDay(stringChangeToDate(startTime), stringChangeToDate(endTime));
				}
			} else {
				if (startTime.substring(11).compareTo("08:00:00") < 0) {
					dDayHour = 8;
				} else if (startTime.substring(11).compareTo("08:00:00") > 0
						&& startTime.substring(11).compareTo("12:00:00") < 0) {
					String tempTime = startTime.substring(0, 10) + " " + "12:00:00";
					dDayHour = getDiscrepantHoursForOneDay(stringChangeToDate(startTime), stringChangeToDate(tempTime))
							+ 4;
				} else if (startTime.substring(11).compareTo("12:00:00") > 0
						&& startTime.substring(11).compareTo("14:00:00") < 0) {
					dDayHour = 4;
				} else if (startTime.substring(11).compareTo("14:00:00") > 0
						&& startTime.substring(11).compareTo("18:00:00") < 0) {
					String tempTime = startTime.substring(0, 10) + " " + "18:00:00";
					dDayHour = getDiscrepantHoursForOneDay(stringChangeToDate(startTime), stringChangeToDate(tempTime));
				}
			}
			iConsumeHours = dDayHour;
		} else {
			// 计算首日耗时
			double dFirstDayHour = 0;
			if (startTime.substring(11).compareTo("08:00:00") < 0) {// 在8:00前
				dFirstDayHour = 8;
			} else if (startTime.substring(11).compareTo("08:00:00") > 0
					&& startTime.substring(11).compareTo("12:00:00") < 0) {// 在8:00-12:00前
				String tempTime = startTime.substring(0, 10) + " " + "12:00:00";
				dFirstDayHour = getDiscrepantHoursForOneDay(stringChangeToDate(startTime), stringChangeToDate(tempTime))
						+ 4;
			} else if (startTime.substring(11).compareTo("12:00:00") > 0
					&& startTime.substring(11).compareTo("14:00:00") < 0) {// 在12:00-14:00前
				dFirstDayHour = 4;
			} else if (startTime.substring(11).compareTo("14:00:00") > 0
					&& startTime.substring(11).compareTo("18:00:00") < 0) {// 在14:00-18:00前
				String tempTime = startTime.substring(0, 10) + " " + "18:00:00";
				dFirstDayHour = getDiscrepantHoursForOneDay(stringChangeToDate(startTime),
						stringChangeToDate(tempTime));
			}

			// 计算最后一天的耗时
			double dLastDayHour = 0;
			System.out.println("endTime.substring(11)=" + endTime.substring(11));
			if (endTime.substring(11).compareTo("08:00:00") < 0) {// 在8:00前
				dLastDayHour = 0;
			} else if (endTime.substring(11).compareTo("08:00:00") > 0
					&& endTime.substring(11).compareTo("12:00") < 0) {// 在8:00-12:00前
				String tempTime = endTime.substring(0, 10) + " " + "08:00:00";
				dLastDayHour = getDiscrepantHoursForOneDay(stringChangeToDate(tempTime), stringChangeToDate(endTime));
			} else if (endTime.substring(11).compareTo("12:00:00") > 0
					&& endTime.substring(11).compareTo("14:00") < 0) {// 在12:00-14:00前
				dLastDayHour = 4;
			} else if (endTime.substring(11).compareTo("14:00:00") > 0
					&& endTime.substring(11).compareTo("18:00") < 0) {// 在14:00-18:00前
				String tempTime = endTime.substring(0, 10) + " " + "14:00:00";
				dLastDayHour = getDiscrepantHoursForOneDay(stringChangeToDate(tempTime), stringChangeToDate(endTime))
						+ 4;
			} else {
				dLastDayHour = 8;
			}

			// 计算中间日期的耗时
			String sMiddleDayHour = CommonBean.integerToString(
					(getDiscrepantDay(stringChangeToDate(startTime), stringChangeToDate(endTime)) - 1) * 8);// 天数*8小时/天

			// System.out.println("dFirstDayHour="+dFirstDayHour+";dLastDayHour="+dLastDayHour+";sMiddleDayHour="+CommonBean.stringToDouble(sMiddleDayHour));
			iConsumeHours = dFirstDayHour + dLastDayHour + CommonBean.stringToDouble(sMiddleDayHour);
		}

		return iConsumeHours;
	}

	/**
	 * 替换身份证的全角字母
	 * 
	 * @param sIdCard
	 * @return
	 */
	public static String replaceIdCardLetter(String sIdCard) {
		String sStr = clearNull(sIdCard);
		if (sStr.indexOf("Ｘ") > -1) {
			sStr = sStr.replace("Ｘ", "X");
		}
		if (sStr.indexOf("ｘ") > -1) {
			sStr = sStr.replace("ｘ", "x");
		}
		if (sStr.indexOf("Ｈ") > -1) {
			sStr = sStr.replace("Ｈ", "H");
		}
		if (sStr.indexOf("ｈ") > -1) {
			sStr = sStr.replace("ｈ", "h");
		}
		if (sStr.indexOf("　") > -1) {
			sStr = sStr.replace("　", "");
		}
		return sStr;
	}

	public static boolean checkIdCard(String sIdCard) {
		boolean bFlag = false;
		int iLength = sIdCard.getBytes().length;
		if (iLength == 15) {
			Pattern idNumPattern = Pattern
					.compile("(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])(\\d{3}|\\d{2}[xX])$)");
			Matcher idNumMatcher = idNumPattern.matcher(sIdCard);
			if (idNumMatcher.matches()) {
				bFlag = true;
			}
		} else if (iLength == 18) {
			Pattern idNumPattern = Pattern
					.compile("(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])(\\d{4}|\\d{3}[xX])$)");
			Matcher idNumMatcher = idNumPattern.matcher(sIdCard);
			if (idNumMatcher.matches()) {
				bFlag = true;
			}
		}
		return bFlag;
	}

	/**
	 * 计算短信条数
	 * 
	 * @return
	 */
	public static int countSmsAmount(String sContent, String sSmsSuffix) {
		// 接收短信
		int iSmsAmount = 0;
		int iContentLength = sContent.getBytes().length;
		// 如果没有后缀则长度要增加后缀长度
		int iCountNameSms = sSmsSuffix.getBytes().length;
		if (!sContent.endsWith(sSmsSuffix)) {
			iContentLength += iCountNameSms;
		}
		if (iContentLength <= 140) {
			iSmsAmount = 1;
		} else {
			iSmsAmount = (int) (iContentLength / 130);
			iSmsAmount = (iContentLength % 130 == 0) ? iSmsAmount : (iSmsAmount + 1);
		}
		return iSmsAmount;
	}

	public static int countSmsAmountWithParameter(String sContent, String sSmsSuffix) {
		// 接收短信
		int iSmsAmount = 0;
		sContent = sContent.replace("{客户名}", "客户名");
		sContent = sContent.replace("{日期}", CommonBean.getNowTime("yyyy-MM-dd"));
		int iContentLength = sContent.getBytes().length;
		// 如果没有后缀则长度要增加后缀长度
		int iCountNameSms = sSmsSuffix.getBytes().length;
		if (!sContent.endsWith(sSmsSuffix)) {
			iContentLength += iCountNameSms;
		}
		if (iContentLength <= 140) {
			iSmsAmount = 1;
		} else {
			iSmsAmount = (int) (iContentLength / 130);
			iSmsAmount = (iContentLength % 130 == 0) ? iSmsAmount : (iSmsAmount + 1);
		}
		return iSmsAmount;
	}

	/**
	 * 计算短信条数(合作机构发短信专用)
	 * 
	 * @return
	 */
	public static int countSmsAmountForCI(String sContent) {
		// 接收短信
		int iSmsAmount = 0;
		int iContentLength = sContent.getBytes().length;
		if (iContentLength <= 140) {
			iSmsAmount = 1;
		} else {
			iSmsAmount = (int) (iContentLength / 130);
			iSmsAmount = (iContentLength % 130 == 0) ? iSmsAmount : (iSmsAmount + 1);
		}
		return iSmsAmount;
	}

	/**
	 * 计算耗时
	 * 
	 * @return
	 */
	public static long getTimeConsumeForSecond(String s_StartTime, String s_EndTime) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		java.util.Date date_StartTime;
		java.util.Date date_EndTime;
		long l = 0l;
		long secord = 0l;
		try {
			date_StartTime = df.parse(s_StartTime);
			date_EndTime = df.parse(s_EndTime);
			l = date_EndTime.getTime() - date_StartTime.getTime();
			secord = l / 1000;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return secord;
	}

	/**
	 * 获取字符编码
	 * 
	 * @return
	 */
	public static String getProjectCharset() {
		return PROJECT_CHARSET;
	}

	/**
	 * 字符串截取
	 * 
	 * @param sValueName
	 * @param iLength
	 * @return
	 */
	public static String getCutOffValue(String sValueName, int iLength) {
		if (iLength > 0) {
			if (sValueName.length() > iLength + 1) {
				sValueName = sValueName.substring(0, iLength) + "...";
			}
		}
		return sValueName;
	}

	/**
	 * 获取折扣（乘10，去掉末位0）
	 * 
	 * @return
	 */
	public static String getDiscountValue(Double dDiscountValue) {
		String sDiscountValue = "";
		sDiscountValue = CommonBean.doubleToString(ArithUtils.mul(dDiscountValue, 10.00));
		while (sDiscountValue.indexOf(".") > -1 && (sDiscountValue.endsWith("0") || sDiscountValue.endsWith("."))) {// 有小数点并已“0”结尾
			sDiscountValue = sDiscountValue.substring(0, sDiscountValue.length() - 1);
		}
		// if (sDiscountValue.substring(sDiscountValue.indexOf(".") +
		// 1).contains("00")) {
		// sDiscountValue = sDiscountValue.substring(0,
		// sDiscountValue.indexOf("."));
		// } else if (sDiscountValue.substring(sDiscountValue.indexOf(".") +
		// 1).contains("0")) {
		// // sDiscountValue = sDiscountValue.substring(0,
		// sDiscountValue.indexOf(".") + 2);
		// // 若xx.0就显示xx，但如果是xx.0x，就直接显示
		// if (sDiscountValue.endsWith(".0")) {
		// sDiscountValue = sDiscountValue.replace(".0", "");
		// }
		// }
		return sDiscountValue;
	}

	/**
	 * 为日期添加分
	 * 
	 * @param date：日期
	 * @param second：秒
	 * @return
	 */
	public static Date dateAddMinute(Date date, int minute) {
		try {
			Calendar bc = Calendar.getInstance();
			bc.setTime(date);
			bc.add(Calendar.MINUTE, minute);
			return bc.getTime();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return date;
	}

	/**
	 * 创建发送短信编号
	 * 
	 * @param date：日期
	 * @param second：秒
	 * @return
	 */
	public static String getSendNumber(String sSmsType) {
		String sSendNumber = "";
		sSendNumber = sSmsType + getNowTime("yyMMddHHmmss") + CommonBean.getRandomNumber(4);
		return sSendNumber;
	}

	/**
	 * 转换日期格式为xxxx-xx-xx，支持xxxx.xx.xx、xxxx/xx/xx格式转换
	 * 
	 * @param sDateStr
	 * @return
	 */
	public static String changeDateFormat(String sDateStr) {
		if ("".equals(CommonBean.clearNull(sDateStr)))
			return sDateStr;
		sDateStr = sDateStr.replace("/", "-");
		sDateStr = sDateStr.replace(".", "-");
		String[] sArr2 = sDateStr.split("-");
		if (sArr2.length == 3) {
			if (sArr2[0] != null && sArr2[0].length() >= 4) {
				sDateStr = sArr2[0] + "-";
				sDateStr += (sArr2[1].length() == 1) ? "0" + sArr2[1] : sArr2[1];
				sDateStr += "-";
				sDateStr += (sArr2[2].length() == 1) ? "0" + sArr2[2] : sArr2[2];
			} else {
				sDateStr = sArr2[2] + "-";
				sDateStr += (sArr2[1].length() == 1) ? "0" + sArr2[1] : sArr2[1];
				sDateStr += "-";
				sDateStr += (sArr2[0].length() == 1) ? "0" + sArr2[0] : sArr2[0];
			}
		} else {
			// System.out.println("不能识别的日期格式=" + sDateStr);
		}
		return sDateStr;
	}

	/**
	 * 转换时间格式为xx:xx:xx，支持x:x:x格式转换
	 * 
	 * @param sTimeStr
	 * @return
	 */
	public static String changeTimeFormat(String sTimeStr) {
		if ("".equals(CommonBean.clearNull(sTimeStr)))
			return sTimeStr;
		String[] sArr2 = sTimeStr.split(":");
		if (sArr2 != null && sArr2.length > 0) {
			sTimeStr = (sArr2[0].length() == 1) ? "0" + sArr2[0] : sArr2[0];
			if (sArr2.length > 1) {
				sTimeStr += ":";
				sTimeStr += (sArr2[1].length() == 1) ? "0" + sArr2[1] : sArr2[1];
			}
			if (sArr2.length > 2) {
				sTimeStr += ":";
				sTimeStr += (sArr2[2].length() == 1) ? "0" + sArr2[2] : sArr2[2];
			}
		} else {
			// System.out.println("不能识别的日期格式=" + sTimeStr);
		}
		return sTimeStr;
	}

	/**
	 * 处理手机号码和联系电话： 手机号码与联系电话写在一起，之间使用换行、tab制表符、顿号（、）连接
	 * 
	 * @param sMobilePhone
	 * @return {手机号码，联系电话}
	 */
	public static String[] handleMobilePhone(String sMobilePhone) {
		String[] arrTemp = { "", "" };
		String sTempPhone = "", sTempMobile = "";
		if (!"".equals(sMobilePhone)) {
			sMobilePhone = sMobilePhone.replace("\r\n", "/");
			sMobilePhone = sMobilePhone.replace("\n", "/");
			sMobilePhone = sMobilePhone.replace("\r", "/");
			sMobilePhone = sMobilePhone.replace("、", "/");
			sMobilePhone = sMobilePhone.replace("无号码", "");
			sMobilePhone = sMobilePhone.replace("无", "");

			String[] sArr = sMobilePhone.split("/");
			if (sArr != null && sArr.length > 1) {
				if (CommonBean.isMobileNumber(sArr[0])) {
					sTempMobile = sArr[0];
				} else {
					sTempPhone = sArr[0];
				}
				if (CommonBean.isMobileNumber(sArr[1])) {
					sTempMobile = sArr[1];
				} else {
					sTempPhone = sArr[1];
				}
			} else if (sArr != null && sArr.length == 1) {
				if (CommonBean.isMobileNumber(sArr[0])) {
					sTempMobile = sArr[0];
				} else {
					sTempPhone = sArr[0];
				}
			}
			arrTemp[0] = sTempMobile;
			arrTemp[1] = sTempPhone;
		}
		return arrTemp;
	}

	/**
	 * 按长度增加空格
	 * 
	 * @param sTempNumber
	 * @param iLength
	 * @return
	 */
	public static String addBlank(String sValueName, int iLength) {
		String sTempNumber = "";
		if (iLength > 0) {
			int iNum = sValueName.length();
			if (iNum > iLength) {
				for (int i = 0; i < iNum; i += iLength) {
					if (i != 0)
						sTempNumber += " ";
					if (i + iLength <= iNum) {
						sTempNumber += sValueName.substring(i, i + iLength);
					} else {
						sTempNumber += sValueName.substring(i, iNum);
					}

				}
			} else {
				sTempNumber = sValueName;
			}
		} else {
			sTempNumber = sValueName;
		}
		return sTempNumber;
	}

	//
	public static Double stringToDouble(String sNum, int num) {
		if ("".equals(clearNull(sNum))) {
			return 0d;
		}
		Double lNum = 0d;
		try {
			// lNum = Double.parseDouble(sNum);
			lNum = changeDouble(sNum, num);
		} catch (Exception e) {
			// System.out.println("Double转型异常！");
		}
		return lNum;
	}

	public static String shieldedValue(String sValueType, String sValue) {
		String sTempValue = sValue;
		if (!"".equals(sValue)) {
			if ("1".equals(sValueType)) {// 身份证(第14位至17位用*号保护)
				if (sValue.length() == 15) {
					sTempValue = sValue.substring(0, 10) + "****" + sValue.substring(14);
				} else if (sValue.length() == 18) {// 屏蔽14-17位
					sTempValue = sValue.substring(0, 13) + "****" + sValue.substring(17);
				}
			} else if ("2".equals(sValueType)) {// 手机号码(第8位至第10位用*号保护)
				if (sValue.length() == 11) {//
					sTempValue = sValue.substring(0, 7) + "***" + sValue.substring(10);
				}
			} else if ("3".equals(sValueType)) {// 联系电话(第6位和第7位用*号保护)
				if ((!sValue.contains("-") && sValue.length() >= 7)) {
					sTempValue = sValue.substring(0, 5) + "**" + sValue.substring(6);
				} else if (sValue.contains("-")) {
					String sNewTempValue = sValue.substring(sValue.indexOf("-") + 1);
					if (sNewTempValue.length() >= 7) {
						int sStartIndex = sValue.indexOf("-") + 6;
						sTempValue = sValue.substring(0, sStartIndex) + "**" + sValue.substring(sStartIndex + 1);
					}
				}
			} else if ("4".equals(sValueType)) {// 住址(第6位至最后用*号保护。)
				String sShielded = "";
				for (int i = 5; i < sValue.length(); i++) {
					sShielded += "*";
				}
				if (sValue.length() >= 6) {//
					sTempValue = sValue.substring(0, 5) + sShielded;
				}
			}
		}
		return sTempValue;
	}

	/**
	 * 获取当天(或当天+n天）到指定的天数的日期列表
	 * 
	 * @param iAdd:当天为0
	 * @param iDay:指定天数
	 * @param sMode:0-全部，1-去除周日，2-去除周六，3-去除周六日
	 * @return 用“|”分隔
	 */
	public static String getDateListForMonth(String sAdd, String sDay, String sMode) {
		String sDateList = "";
		if ("".equals(CommonBean.clearNull(sAdd)) || "".equals(CommonBean.clearNull(sDay)))
			return sDateList;
		sMode = CommonBean.clearNull(sMode, "0");
		String sNowDay = CommonBean.getNowTime("yyyy-MM-dd");
		int iDayForWeek = CommonBean.dayForWeek(sNowDay);
		int iAdd = CommonBean.stringToInteger(sAdd);
		int iDay = CommonBean.stringToInteger(sDay);
		if (iAdd > 0) {
			sNowDay = CommonBean.addDate(sNowDay, iAdd, "yyyy-MM-dd");
		}
		if (iDay == 0) {
			if ("0".equals(sMode) || ("1".equals(sMode) && iDayForWeek != 6) || ("2".equals(sMode) && iDayForWeek != 7)
					|| ("3".equals(sMode) && iDayForWeek != 6 && iDayForWeek != 7)) {
				sDateList += sNowDay;
			}
		} else {
			for (int i = 0; i < iDay; i++) {
				if ("0".equals(sMode) || ("1".equals(sMode) && iDayForWeek != 6)
						|| ("2".equals(sMode) && iDayForWeek != 7)
						|| ("3".equals(sMode) && iDayForWeek != 6 && iDayForWeek != 7)) {
					if (!"".equals(sDateList))
						sDateList += "|";
					sDateList += sNowDay;
				} else {
					i--;
				}
				sNowDay = CommonBean.addDate(sNowDay, 1, "yyyy-MM-dd");
				iDayForWeek = CommonBean.dayForWeek(sNowDay);
			}
		}
		return sDateList;
	}

	/**
	 * 获取时间间隔列表
	 * 
	 * @return
	 */
	public static String getTimeListForDate(String sTime) {
		String sTimeList = "";
		if ("".equals(CommonBean.clearNull(sTime)) || sTime.indexOf("~") < 0 || "~".equals(sTime)
				|| sTime.startsWith("~") || sTime.endsWith("~")) {
			sTimeList = "";
		} else {
			String[] sArrTime = sTime.split("~");
			String[] sStart = sArrTime[0].split(":");
			String[] sEnd = sArrTime[1].split(":");
			int iStart = CommonBean.stringToInteger(sStart[0]), iEnd = CommonBean.stringToInteger(sEnd[0]);
			String sStartTime = sArrTime[0], sEndTime = "";
			if (iEnd > iStart) {
				// 结束时间
				if (!sStartTime.endsWith(":00")) {
					iStart++;
					if (iStart < 10) {
						sEndTime = "0" + iStart + ":00";
					} else {
						sEndTime = iStart + ":00";
					}
					sTimeList = sStartTime + "-" + sEndTime;
					sStartTime = sEndTime;
				}
				while (iEnd >= iStart) {
					iStart++;
					if (iStart <= iEnd) {
						if (iStart < 10) {
							sEndTime = "0" + iStart + ":00";
						} else {
							sEndTime = iStart + ":00";
						}
						if (!"".equals(sTimeList))
							sTimeList += "|";
						sTimeList += sStartTime + "-" + sEndTime;
						sStartTime = sEndTime;
					}
				}
				if (!sArrTime[1].endsWith(":00")) {
					if (!"".equals(sTimeList))
						sTimeList += "|";
					sTimeList += sStartTime + "-" + sArrTime[1];
				}
			} else {
				sTimeList = sStartTime + "-" + sEndTime;
			}

		}
		return sTimeList;
	}

	/**
	 * 获取活动码
	 * 
	 * @return
	 */
	public static String getActivityCode(String sType, int iNum) {
		if (iNum < 0)
			return "";
		String sNumber = "1,2,3,4,5,6,7,8,9,0";
		String sBig = "A,B,C,D,E,F,G,H,I,G,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
		String sSmall = "a,b,c,d,e,f,g,h,i,g,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
		StringBuffer buf = new StringBuffer();
		if ("1".equals(sType)) {// 纯数字
			buf.append(sNumber);
		} else if ("2".equals(sType)) {// 纯字母（全小写）
			buf.append(sSmall);
		} else if ("3".equals(sType)) {// 纯字母（大小写混合）
			buf.append(sBig + "," + sSmall);
		} else if ("4".equals(sType)) {// 数字和字母（全小写）
			buf.append(sNumber + "," + sSmall);
		} else if ("5".equals(sType)) {// 数字和字母（大小写混合）
			buf.append(sNumber + "," + sBig + "," + sNumber + "," + sSmall);// 增加数字出现机率
		}
		StringBuffer b = new StringBuffer();
		int k;
		String[] arr = buf.toString().split(",");
		Random r = new Random();
		for (int i = 0; i < iNum; i++) {
			k = r.nextInt(arr.length);
			b.append(String.valueOf(arr[k]));
		}
		return b.toString();
	}

	// 获取付费服务大类名称
	public static String getProductCategoryOne(String sCategoryNumberOne) {
		String sCategoryNameOne = "";
		if ("1".equals(sCategoryNumberOne)) {
			sCategoryNameOne = "保健服务";
		} else if ("2".equals(sCategoryNumberOne)) {
			sCategoryNameOne = "医疗服务";
		} else if ("3".equals(sCategoryNumberOne)) {
			sCategoryNameOne = "家政服务";
		}
		return sCategoryNameOne;
	}

	/**
	 * 判断是否微信浏览器
	 * 
	 * @param request：当前请求
	 * @return
	 */
	public static boolean isWeiXinBrowser(HttpServletRequest request) {
		boolean bWeiXin = false;
		try {
			String sUserAgent = request.getHeader("USER-AGENT");
			if (sUserAgent != null && sUserAgent.toLowerCase().indexOf("micromessenger") > -1) {
				bWeiXin = true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bWeiXin;
	}

	/**
	 * 详细信息显示
	 * 
	 * @param sDetail
	 * @param request
	 * @return
	 */
	public static String detailShow(String sDetail, HttpServletRequest request) {
		if (sDetail.indexOf("\n") > -1 && sDetail.indexOf("<p>") == -1 && sDetail.indexOf("<img") == -1) {
			sDetail = sDetail.replace("\r\n", "<br/>");
			sDetail = sDetail.replace("\n", "<br/>");
		}
		String sUrl = request.getScheme() + "://" + request.getServerName();
		sUrl += ":" + request.getServerPort() + request.getContextPath();
		if (sDetail != null && isWindowsOS()) {
			sDetail = sDetail.replace(" src=\"/img_", " src=\"" + sUrl + filePath + "/img_");
		} else {
			sDetail = sDetail.replace(" src=\"/img_", " src=\"" + sUrl + "/img_");
		}
		return sDetail;
	}

	/**
	 * 获取图片的绝对路径
	 * 
	 * @param url
	 * @param request
	 * @return
	 */
	public static String getAbsoluteUrl(String url, HttpServletRequest request) {
		String basePath = CommonBean.getPageUrl(request);
		return getAbsoluteUrl(url, basePath);
	}

	/**
	 * 获取图片的绝对路径
	 * 
	 * @param url
	 * @param basePath
	 * @return
	 */
	public static String getAbsoluteUrl(String url, String basePath) {
		if (isWindowsOS() && url.indexOf("img_") > -1) {
			url = basePath + filePath + url;
		} else if (isWindowsOS() && url.indexOf("mda_") > -1) {
			url = basePath + filePath + url;
		} else {
			url = basePath + url;
		}
		return url;
	}

	/**
	 * 过滤地址的固定值（例如：直辖乡）
	 * 
	 * @param sFullAddress
	 * @return
	 */
	public static String filterAddress(String sFullAddress) {
		if (sFullAddress == null || "".equals(sFullAddress))
			return "";
		sFullAddress = sFullAddress.replace("直辖乡", "");
		return sFullAddress;
	}

	/**
	 * 根据项目部署的环境获取路径
	 * 
	 * @return
	 */
	public static String getFullPath(String sSavePath) {
		String sFullPath = sSavePath;
		if (isWindowsOS() || !sSavePath.startsWith("/")) {
			if (sSavePath.startsWith("/")) {
				sFullPath = getProjectPath() + sSavePath;
			} else {
				sFullPath = getProjectPath() + "/" + sSavePath;
			}
		}
		return sFullPath;
	}

	/**
	 * 获取当前月份的第一天
	 * 
	 * @return
	 */
	public static String getFirstDayOfMonth() {
		Calendar calCalendar = Calendar.getInstance();
		calCalendar.set(Calendar.DATE, calCalendar.getActualMinimum(Calendar.DATE));
		calCalendar.set(Calendar.HOUR_OF_DAY, calCalendar.getActualMinimum(Calendar.HOUR_OF_DAY));
		calCalendar.set(Calendar.MINUTE, calCalendar.getActualMinimum(Calendar.MINUTE));
		calCalendar.set(Calendar.SECOND, calCalendar.getActualMinimum(Calendar.SECOND));
		return CommonBean.dateToString(calCalendar.getTime(), "yyyy-MM-dd HH:mm:ss");
	}

	/**
	 * 获取当前月份的最后一天
	 * 
	 * @return
	 */
	public static String getLastDayOfMonth() {
		Calendar calCalendar = Calendar.getInstance();
		calCalendar.set(Calendar.DATE, calCalendar.getActualMaximum(Calendar.DATE));
		calCalendar.set(Calendar.HOUR_OF_DAY, calCalendar.getActualMaximum(Calendar.HOUR_OF_DAY));
		calCalendar.set(Calendar.MINUTE, calCalendar.getActualMaximum(Calendar.MINUTE));
		calCalendar.set(Calendar.SECOND, calCalendar.getActualMaximum(Calendar.SECOND));
		return CommonBean.dateToString(calCalendar.getTime(), "yyyy-MM-dd HH:mm:ss");
	}

	// /**
	// * 使用BASE64加密
	// * @param sSource
	// * @return
	// */
	// public static String encodeBase64(byte[] arrBytes) {
	// if (arrBytes == null || arrBytes.length == 0) { return ""; }
	// return new Base64Encoder().encode(arrBytes);
	// }
	//
	// /**
	// * 使用BASE64解密
	// * @param sCode
	// * @return
	// */
	// public static byte[] decodeBase64(String sCode) {
	// if (StringUtils.isEmpty(sCode)) { return new byte[0]; }
	// try {
	// return new BASE64Decoder().decodeBuffer(sCode);
	// } catch (Exception e) {
	// System.out.println("使用Base64解码时发生错误！");
	// e.printStackTrace();
	// }
	// return new byte[0];
	// }

	/**
	 * 将列表转换成数组
	 * 
	 * @param list
	 * @param clazz
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static <T> T[] listToArray(List<T> list, Class<T> clazz) {
		if (list == null || list.size() == 0) {
			return (T[]) Array.newInstance(clazz, 0);
		}
		T[] arrResult = (T[]) Array.newInstance(clazz, list.size());
		return list.toArray(arrResult);
	}

	/**
	 * 秒数转换为天时分
	 * 
	 * @param sSecond
	 * @return
	 */
	public static String secondConvertDayHourMin(String sSecond) {
		Long lSecond = CommonBean.stringToLong(sSecond);
		if (lSecond == null)
			return "";
		String sDayHourMin = "";// xx天xx小时xx分
		Long lTempSecond = lSecond;
		Long lDay = 60l * 60 * 24, lHour = 60l * 60, lMin = 60l;
		if (lTempSecond >= lDay) {// 天 60*60*24
			if (lTempSecond / lDay >= 0) {
				sDayHourMin += lTempSecond / lDay + "天";
			}
			while (lTempSecond >= lDay) {
				lTempSecond = lTempSecond % lDay;
			}
		}
		if (lTempSecond >= lHour) {// 小时 60*60
			if (lTempSecond / lHour >= 0) {
				sDayHourMin += lTempSecond / lHour + "小时";
			}
			while (lTempSecond >= lHour) {
				lTempSecond = lTempSecond % lHour;
			}
		}
		if (lTempSecond > 0) {
			if (lTempSecond < lMin) {
				sDayHourMin += "1分钟";
			} else {
				sDayHourMin += lTempSecond / lMin + "分钟";
			}
		}
		return sDayHourMin;
	}

	/**
	 * 浮点型或整形（当数值的小数位不是0就显示小数位，否则就不显示）
	 * 
	 * @param sTempValue
	 * @return
	 */
	public static String doubleOrLongValue(String sTempValue) {
		sTempValue = CommonBean.doubleToString(CommonBean.stringToDouble(sTempValue, 4), "##0.0000");// 将小数位扩展为4位再进行判断
		if (sTempValue != null && sTempValue.indexOf(".") > -1) {
			// if (sTempValue.substring(sTempValue.indexOf(".") +
			// 1).contains("00")) {
			// sTempValue = sTempValue.substring(0, sTempValue.indexOf("."));
			// } else if (sTempValue.substring(sTempValue.indexOf(".") +
			// 1).contains("0")) {
			// if (sTempValue.endsWith(".0")) {// 暂不支持xx.0x0的格式，有需要再支持
			// sTempValue = sTempValue.replace(".0", "");
			// }
			// }
			do {
				if (sTempValue.endsWith(".0")) {
					sTempValue = sTempValue.replace(".0", "");
				} else {
					sTempValue = sTempValue.substring(0, sTempValue.length() - 1);
				}
			} while (sTempValue.indexOf(".") > -1 && sTempValue.endsWith("0"));

		}
		return sTempValue;
	}

	/**
	 * 获取亲属好友关系
	 * 
	 * @param sValue
	 * @return
	 */
	public static String toFamilyRole(String sValue) {
		if (StringUtils.isEmpty(sValue)) {
			return "";
		} else if ("0".equals(sValue)) {
			return "自己";
		} else if ("1".equals(sValue)) {
			return "父亲";
		} else if ("2".equals(sValue)) {
			return "母亲";
		} else if ("3".equals(sValue)) {
			return "爷爷";
		} else if ("4".equals(sValue)) {
			return "奶奶";
		} else if ("5".equals(sValue)) {
			return "外公";
		} else if ("6".equals(sValue)) {
			return "外婆";
		} else if ("7".equals(sValue)) {
			return "岳父";
		} else if ("8".equals(sValue)) {
			return "岳母";
		} else if ("9".equals(sValue)) {
			return "丈夫";
		} else if ("10".equals(sValue)) {
			return "妻子";
		} else if ("11".equals(sValue)) {
			return "儿子";
		} else if ("12".equals(sValue)) {
			return "女儿";
		} else if ("13".equals(sValue)) {
			return "朋友";
		} else if ("14".equals(sValue)) {
			return "其他亲属";
		} else if ("15".equals(sValue)) {
			return "哥哥";
		} else if ("16".equals(sValue)) {
			return "弟弟";
		} else if ("17".equals(sValue)) {
			return "姐姐";
		} else if ("18".equals(sValue)) {
			return "妹妹";
		} else if ("19".equals(sValue)) {
			return "公公";
		} else if ("20".equals(sValue)) {
			return "婆婆";
		} else {
			return "";
		}
	}

	/**
	 * 获取手机后四位，生成登录密码
	 * 
	 * @param sMobilePhoneNumber
	 * @return
	 */
	public static String getMobilePhonePassword(String sMobilePhoneNumber) {
		if (sMobilePhoneNumber == null || "".equals(sMobilePhoneNumber)
				|| !CommonBean.isMobileNumber(sMobilePhoneNumber))
			return "";
		String sPassword = sMobilePhoneNumber;
		sPassword = sPassword.substring(sPassword.length() - 4, sPassword.length());
		sPassword = MD5Utils.getEncryption(sPassword);
		return sPassword;
	}

	/**
	 * 获取当前时间范围，1-上午、2-中午、3-下午、4-晚上
	 * 
	 * @return
	 */
	public static String getCurrentTimeRange() {
		String sRange = "";
		String sNowTime = CommonBean.getNowTime("HH:mm");
		if (sNowTime.compareTo("00:00") >= 0 && sNowTime.compareTo("11:59") <= 0) {
			sRange = "1";
		} else if (sNowTime.compareTo("12:00") >= 0 && sNowTime.compareTo("13:59") <= 0) {
			sRange = "2";
		} else if (sNowTime.compareTo("14:00") >= 0 && sNowTime.compareTo("18:59") <= 0) {
			sRange = "3";
		} else if (sNowTime.compareTo("19:00") >= 0 && sNowTime.compareTo("23:59") <= 0) {
			sRange = "4";
		}
		return sRange;
	}

	/**
	 * 获取属于该请求的cookie值
	 * 
	 * @param request
	 * @param sKey
	 * @return
	 */
	public static String getCookieValue(HttpServletRequest request, String sKey) {
		String sValue = "";
		if (sKey == null || "".equals(sKey))
			return null;
		try {
			Cookie[] cookies = request.getCookies();
			if (cookies != null) {
				for (Cookie coo : cookies) {
					String sName = coo.getName();
					String sTemp = coo.getValue();
					if (sKey.equals(sName) && sTemp != null && !"".equals(sTemp)) {
						sValue = sTemp;
						break;
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			sValue = null;
		}
		return sValue;
	}

	/**
	 * 将驼峰标识转换为下划线
	 * 
	 * @param sValue
	 * @return
	 */
	public static String toUnderlineString(String sValue) {
		StringBuilder sbResult = new StringBuilder();
		if (sValue != null && sValue.length() > 0) {
			sbResult.append(sValue.substring(0, 1));
			for (int i = 1; i < sValue.length(); i++) {
				String s = sValue.substring(i, i + 1);
				if (s.equals(s.toUpperCase()) && !Character.isDigit(s.charAt(0))) {
					sbResult.append("_");
				}
				sbResult.append(s);
			}
		}
		return sbResult.toString().toLowerCase();
	}

	/**
	 * 将字符串转成驼峰字符串
	 * 
	 * @param sValue
	 * @return
	 */
	public static String toHumpString(String sValue) {
		StringBuilder sbResult = new StringBuilder();
		// 快速检查
		if (sValue == null || sValue.isEmpty()) {
			// 没必要转换
			return "";
		} else if (!sValue.contains("_")) {
			// 不含下划线，仅将首字母小写
			return sValue.substring(0, 1).toLowerCase() + sValue.substring(1);
		}
		// 用下划线将原始字符串分割
		String camels[] = sValue.split("_");
		for (String camel : camels) {
			// 跳过原始字符串中开头、结尾的下换线或双重下划线
			if (camel.isEmpty()) {
				continue;
			}
			// 处理真正的驼峰片段
			if (sbResult.length() == 0) {
				// 第一个驼峰片段，全部字母都小写
				sbResult.append(camel.toLowerCase());
			} else {
				// 其他的驼峰片段，首字母大写
				sbResult.append(camel.substring(0, 1).toUpperCase());
				sbResult.append(camel.substring(1).toLowerCase());
			}
		}
		return sbResult.toString();
	}

	/**
	 * 获取table的名称
	 * 
	 * @param po
	 * @return
	 */
	public static String getTableName(Class<?> clsObject) {
		if (clsObject.isAnnotationPresent(Table.class)) {
			return clsObject.getAnnotation(Table.class).name();
		} else {
			return toUnderlineString(clsObject.getSimpleName());
		}
	}

	/**
	 * 获取对象字段的名称
	 * 
	 * @param Field
	 *            原字段
	 * @return
	 */
	public static String getFieldName(Object objObject, Class<?> clsObject, String sFieldName) {
		String sFieldNameResult = "";
		if (objObject == null || clsObject == null || StringUtils.isEmpty(sFieldName))
			return sFieldNameResult;
		try {
			String sFirstLetter = sFieldName.substring(0, 1).toUpperCase();
			String sGetter = "get" + sFirstLetter + sFieldName.substring(1);
			Method method = clsObject.getMethod(sGetter, new Class[] {});
			JoinColumn jc = method.getAnnotation(JoinColumn.class);
			if (jc != null && !StringUtils.isEmpty(jc.name()))
				sFieldNameResult = jc.name();
			Column c = method.getAnnotation(Column.class);
			if (c != null && !StringUtils.isEmpty(c.name()))
				sFieldNameResult = c.name();
			if (jc == null && c == null) {
				sFieldNameResult = toUnderlineString(sFieldName);
			}
		} catch (Exception e) {
			sFieldNameResult = "";
		}
		return sFieldNameResult;
	}

	/**
	 * 获取对象字段的值
	 * 
	 * @param objObject 原对象
	 * @param clsObject 对象class
	 * @param sFieldName 字段名称
	 * @return
	 */
	public static Object[] getFieldValue(Object objObject, Class<?> clsObject, String sFieldName) {
		Object[] objValue = new Object[] { null, 0, "" };
		if (objObject == null || clsObject == null || StringUtils.isEmpty(sFieldName))
			return objValue;
		try {
			String sFirstLetter = sFieldName.substring(0, 1).toUpperCase();
			String sGetter = "get" + sFirstLetter + sFieldName.substring(1);
			Method method = clsObject.getMethod(sGetter, new Class[] {});
			objValue = new Object[] { method.invoke(objObject, new Object[] {}), 1 };
			// 如果是外键，返回外键的值
			JoinColumn jc = method.getAnnotation(JoinColumn.class);
			if (jc != null && !StringUtils.isEmpty(jc.name())) {
				Object objForeignkeyValue = method.invoke(objObject, new Object[] {});
				method = objForeignkeyValue.getClass().getMethod("getId", new Class[] {});
				objValue = new Object[] { method.invoke(objForeignkeyValue, new Object[] {}), 1 };
			}
		} catch (Exception e) {
			objValue = new Object[] { null, -1 };
		}
		return objValue;
	}

	/**
	 * 将map对象转换成java对象
	 * 
	 * @param map
	 * @param beanClass
	 * @return object
	 */
	public static Object mapToObject(Map<String, Object> map, Class<?> beanClass) {
		if (null == map) {
			return null;
		}
		Object obj = null;
		try {
			obj = beanClass.newInstance();
			Field[] fields = obj.getClass().getDeclaredFields();
			for (Field field : fields) {
				String sFirstLetter = field.getName().substring(0, 1).toUpperCase();
				String sGetter = "get" + sFirstLetter + field.getName().substring(1);
				Method method = beanClass.getMethod(sGetter, new Class[] {});
				JoinColumn jc = method.getAnnotation(JoinColumn.class);
				if (jc != null && !StringUtils.isEmpty(jc.name())) {
					String filedName = jc.name();
					if (null == map.get(filedName)) {
						continue;
					}
					Class<?> clsForeignkey = method.getReturnType();
					Object objForeignkey = clsForeignkey.newInstance();
					Field fieldForeign = clsForeignkey.getDeclaredField("id");
					fieldForeign.setAccessible(true);
					fieldForeign.set(objForeignkey, map.get(filedName));
					field.setAccessible(true);
					field.set(obj, objForeignkey);
					continue;
				}
				String filedName = CommonBean.toUnderlineString(field.getName());
				if (null == map.get(filedName)) {
					continue;
				}
				field.setAccessible(true);
				field.set(obj, map.get(filedName));
			}
		} catch (Exception e) {
			System.out.println(CommonBean.getNowTime() + "map转objec对象程序出错！");
			e.printStackTrace();
		}
		return obj;
	}

	/**
	 * 抛出业务异常。
	 * 
	 * @param sMessage
	 */
	public static void throwException(String sMessage) {
		throw new ProcessException(sMessage);
	}

	/**
	 * 判断MessageVo的返回结果，若失败则抛出业务异常。
	 * 
	 * @param mvoResult
	 *            MessageVo
	 */
	public static void throwExceptionIfFail(ResultVo rvoResult) {
		if (rvoResult != null && !rvoResult.isSuccess()) {
			throw new ProcessException();
		}
	}

	/**
	 * 判断MessageVo的返回结果，若失败则抛出业务异常。
	 * 
	 * @param mvoResult
	 *            MessageVo
	 * @param sThrowText
	 *            错误信息
	 */
	public static void throwExceptionIfFail(ResultVo rvoResult, String sMessage) {
		if (rvoResult != null && !rvoResult.isSuccess()) {
			throw new ProcessException(sMessage);
		}
	}

	/**
	 * 生成验证码方法
	 * 
	 * @param args
	 * @throws Exception
	 */
	public static BufferedImage getValidateCode(HttpServletRequest request, String sUuid,
			Map<String, String[]> mapValidateCode) throws Exception {
		// System.out.println("生成验证码");
		Long iBeginTime = System.currentTimeMillis();
		// 在内存中创建图象
		int width = 80, height = 30, count = 4;
		BufferedImage image = null;
		Graphics g = null;
		Random random = null;
		HttpSession session = request.getSession();
		try {
			image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
			// 获取图形上下文
			g = image.getGraphics();
			// 生成随机类
			random = new Random();
			// 设定背景色
			g.setColor(getRandColor(200, 250));
			g.fillRect(0, 0, width, height);
			// 设定字体
			g.setFont(new Font("Times New Roman", Font.PLAIN, 30));
			// 随机产生155条干扰线，使图象中的认证码不易被其它程序探测到
			g.setColor(getRandColor(160, 200));
			for (int i = 0; i < 200; i++) {
				int x = random.nextInt(width);
				int y = random.nextInt(height);
				int xl = random.nextInt(12);
				int yl = random.nextInt(12);
				g.drawLine(x, y, x + xl, y + yl);
			}
			// System.out.println("生成验证码耗时1=" + (System.currentTimeMillis() -
			// iBeginTime));
			// 取随机产生的认证码(x位数字)
			String sRand = "";
			for (int i = 0; i < count; i++) {
				String rand = String.valueOf(random.nextInt(10));
				sRand += rand;
				// 将认证码显示到图象中
				g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
				// 调用函数出来的颜色相同，可能是因为种子太接近，所以只能直接生成
				g.drawString(rand, 18 * i + 6, 26);
			}
			// System.out.println("生成验证码耗时2=" + (System.currentTimeMillis() -
			// iBeginTime));
			// 将认证码存入SESSION
			if (StringUtils.isEmpty(sUuid)) {
				session.setAttribute("ValidateCode", sRand);
			} else {
				if (mapValidateCode != null)
					mapValidateCode.put(sUuid, new String[] { sRand, getNowTime(), "1" });
			}
			// 图象生效
			g.dispose();
			System.out.println(CommonBean.getNowTime() + "(" + request.getServerName() + ")生成验证码耗时="
					+ (System.currentTimeMillis() - iBeginTime));
		} catch (Exception e) {
			System.out.println("ValidateCodeAction生成验证码程序出错...");
			e.printStackTrace();
		}
		return image;
	}

	/**
	 * 给定范围获得随机颜色
	 * 
	 * @param fc
	 * @param bc
	 * @return
	 */
	private static Color getRandColor(int fc, int bc) {
		Random random = new Random();
		if (fc > 255)
			fc = 255;
		if (bc > 255)
			bc = 255;
		int r = fc + random.nextInt(bc - fc);
		int g = fc + random.nextInt(bc - fc);
		int b = fc + random.nextInt(bc - fc);
		random = null;
		return new Color(r, g, b);
	}

	// 对dataMap对象进行处理
	public static Map<String, Object> dealDataMap(Map<String, String> dataMap) throws Exception {
		Map<String, Object> result = new HashMap<String, Object>();
		for (Entry<String, String> vo : dataMap.entrySet()) {
			String sKey = vo.getKey();
			String sValue = vo.getValue();

			// 判断sValue是否含有 "&"
			String[] StrArray = null;
			if (sValue.indexOf("&#") != -1) {
				// 对字符进行切割
				StrArray = sValue.split("&#");
			} else {
				StrArray = new String[] { sValue };
			}
			ObjectMapper mapper = new ObjectMapper();
			Map<String, Object> data = new HashMap<String, Object>();
			List<Object> lst = new ArrayList<Object>();
			String sValueTemp = "";
			Map<String, Object> mapZeroValue = new HashMap<String, Object>();
			for (int j = 0; j < StrArray.length; j++) {
				ObjectMapper mapperTemp = new ObjectMapper();
				JsonNode nodeTemp = mapperTemp.readTree(StrArray[j]);
				data.put("type", nodeTemp.get("type"));
				JsonNode optionTemp = nodeTemp.path("option");
				Map<String, Object> dataTemp = null;
				for (int k = 0; k < optionTemp.size(); k++) {
					for (int n = 0; n < lst.size(); n++) {
						String sTemp = lst.get(n).toString();
						sTemp = sTemp.substring(sTemp.indexOf("value") + 6, sTemp.length() - 1);
						sValueTemp = sValueTemp + sTemp + "&";
					}
					String sTemp = optionTemp.get(k).get("value").toString();
					if (!StringUtils.isEmpty(sTemp) && Arrays.asList(sValueTemp.split("&")).contains(sTemp)) {
						continue;
					}
					if ("0".equals(optionTemp.get(k).get("value").toString())) {
						mapZeroValue.put("value", optionTemp.get(k).get("value").toString());
						mapZeroValue.put("text",
								optionTemp.get(k).get("text").toString().replaceAll("\"", "").replace("\\n", ""));
					} else {
						dataTemp = new HashMap<String, Object>();
						dataTemp.put("value", optionTemp.get(k).get("value").toString());
						dataTemp.put("text",
								optionTemp.get(k).get("text").toString().replaceAll("\"", "").replace("\\n", ""));
						lst.add(dataTemp);
					}
				}
			}
			if (mapZeroValue.size() > 0)
				lst.add(mapZeroValue);
			data.put("option", lst);
			result.put(sKey, mapper.writeValueAsString(data));
		}
		return result;
	}

	// 微信小程序根据code获取unionId和openId
	public static Map<String, String> getUnionIdOpenId(String sCode) {
		Map<String, String> dataMap = new HashMap<String, String>();
		try {
			Map<String, String> param = new HashMap<String, String>();
			param.put("appid", "wx1da2a70511e15e73");
			param.put("secret", "52550897d15c2abf3b25147179f14682");
			param.put("js_code", sCode);
			param.put("grant_type", "authorization_code");
			String result = HttpClientUtils.doGet("https://api.weixin.qq.com/sns/jscode2session", param);
			ObjectMapper mapper = new ObjectMapper();
			JsonNode root = mapper.readTree(result);
			if (root != null && root.hasNonNull("openid")) {
				dataMap.put("openid", root.get("openid").asText());
				if (root.hasNonNull("unionid")) {
					dataMap.put("unionid", root.get("unionid").asText());
				}
			} else {
				System.out.println(CommonBean.getNowTime() + "unionid，openid获取失败！");
			}
		} catch (Exception e) {
			System.out.println(CommonBean.getNowTime() + "unionid，openid获取失败！");
		}
		return dataMap;
	}

	// 微信获取access_token
	public static String getAccessToken() {
		String sResult = "";
		try {
			Map<String, String> param = new HashMap<String, String>();
			param.put("appid", "wx1da2a70511e15e73");
			param.put("secret", "52550897d15c2abf3b25147179f14682");
			param.put("grant_type", "client_credential");
			String result = HttpClientUtils.doGet("https://api.weixin.qq.com/cgi-bin/token", param);
			System.out.println(CommonBean.getNowTime() + "获取结果：" + result);
			ObjectMapper mapper = new ObjectMapper();
			JsonNode root = mapper.readTree(result);
			if (root != null && root.hasNonNull("access_token")) {
				sResult = root.get("access_token").toString();
				sResult = sResult.replace("\"", "");
				System.out.println(CommonBean.getNowTime() + "access_token获取成功！" + sResult);
			} else {
				System.out.println(CommonBean.getNowTime() + "access_token获取失败！");
			}
		} catch (Exception e) {
			System.out.println(CommonBean.getNowTime() + "access_token获取失败！");
			// e.printStackTrace();
		}
		return sResult;
	}

	// 获取微信小程序二维码方法
	public static byte[] getWxQrCode(String sScene, String sAccessToken) {
		try {
			String sUrl = "http://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + sAccessToken;
			Map<String, String> paramMap = new HashMap<String, String>();
			paramMap.put("scene", sScene);
			byte[] sResult = HttpClientUtils.doPostJson(sUrl, JsonUtils.objectToJson(paramMap));
			return sResult;
		} catch (Exception e) {
			System.out.println("微信小程序获取失败！");
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 获得Exception堆栈信息 将Exception堆栈信息打印到日志中
	 * 
	 * @return 堆栈信息字符串
	 */
	public static String getExceptionStack(Exception e) {
		StringWriter swStackMsg = new StringWriter();
		PrintWriter pwStackMsg = new PrintWriter(swStackMsg);
		e.printStackTrace(pwStackMsg);
		// org.slf4j.Logger logger = LoggerFactory.getLogger(CommonBean.class);
		// logger.error(swStackMsg.toString());
		return swStackMsg.toString();
	}

	/**
	 * 生成微信小程序的token
	 * 
	 * @param sOpenId
	 *            微信的openId
	 * @param sId
	 *            登录用户id(id1-id2)(账号id-微信账号id)
	 * @param sRole
	 *            用户角色2-机构3-渠道
	 * @param sType
	 *            登录类型1app账号 2微信账号
	 * @param sProjectProduction
	 *            当前项目的环境
	 * @return
	 */
	public static String generationWxToken(String sOpenId, String sId, String sRole, String sType,
			String sProjectProduction) {
		DesUtils des = new DesUtils();// 默认密钥
		if ("".equals(sOpenId) || "".equals(sId) || "".equals(sRole) || "".equals(sType)) {
			return null;
		} else {
			String sResult = sOpenId + "," + sId + "," + CommonBean.getNowTime("yyyyMMddHHmm") + "," + sRole + ","
					+ sType + "," + sProjectProduction;
			return des.encrypt(sResult);
		}
	}

	/**
	 * 获取spring中的bean对象
	 * 
	 * @param servletContext
	 * @param sBeanName
	 *            要获取bean的名称
	 * @return
	 */
	public static Object getSpringBean(ServletContext servletContext, String sBeanName) {
		if (null != servletContext) {
			ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
			if (null != applicationContext) {
				return applicationContext.getBean(sBeanName);
			} else {
				return null;
			}
		} else {
			return null;
		}
	}

	/**
	 * 获取URL编码，支持含有emoji表情的值转换
	 * 
	 * @param sStr
	 * @param sCharsetName
	 * @return
	 */
	public static String getURLEncoder(String sStr, String sCharsetName) {
		if (sStr == null || "".equals(sStr))
			return sStr;
		try {
			sStr = URLEncoder.encode(sStr, clearNull(sCharsetName, "UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sStr;
	}

	/**
	 * 获取URL解码，支持含有emoji表情的值转换
	 * 
	 * @param sStr
	 * @param sCharsetName
	 * @return
	 */
	public static String getURLDecoder(String sStr, String sCharsetName) {
		if (sStr == null || "".equals(sStr))
			return sStr;
		try {
			sStr = URLDecoder.decode(sStr, clearNull(sCharsetName, "UTF-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sStr;
	}

	/**
	 * 替换html字符实体
	 * 
	 * @param sStr
	 * @param bReplaceLtGt:是否替换><号
	 * @return
	 */
	public static String replaceEscapeCharacter(String sStr, boolean bReplaceLtGt) {
		if (sStr == null || "".equals(sStr))
			return sStr;
		try {
			sStr = sStr.replace("&nbsp;", "");
			sStr = sStr.replace("&ensp;", "");
			sStr = sStr.replace("&mu;", "μ");
			sStr = sStr.replace("&alpha;", "α");
			sStr = sStr.replace("&beta;", "β");
			if (bReplaceLtGt) {
				sStr = sStr.replace("&lt;", "<");
				sStr = sStr.replace("&gt;", ">");
			}
			sStr = sStr.replace("&le;", "≤");
			sStr = sStr.replace("&ge;", "≥");
			sStr = sStr.replace("&plusmn;", "±");
			sStr = sStr.replace("&times;", "×");
			sStr = sStr.replace("&divide;", "÷");
			sStr = sStr.replace("&quot;", "\"");
			sStr = sStr.replace("&apos;", "'");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sStr;
	}

	/**
	 * 重新计算合作伙伴显示的位置
	 * 
	 * @param cooperativepaertner
	 * @param id
	 * @return
	 */
	public static String dealCooperativePartner(String cooperativepaertner, String id) {
		boolean bIsChange = true;
		String sResult = id + ",";
		String[] strCp = cooperativepaertner.split(",");
		for (int i = 0; i < strCp.length; i++) {
			if (strCp[i].equals(id)) {
				if (i < strCp.length / 2) {
					bIsChange = false;
				}
				continue;
			}
			if (!Arrays.asList(strCp).contains(id) && i == strCp.length - 1) {
				continue;
			}
			sResult = sResult + strCp[i] + ",";
		}
		sResult = sResult.substring(0, sResult.length() - 1);
		if (bIsChange) {
			String[] strTemp = sResult.split(",");
			for (int i = 0; i < strTemp.length; i++) {
				if (i == strTemp.length / 2) {
					String sTemp = strTemp[i];
					strTemp[i] = strTemp[i + 1];
					strTemp[i + 1] = sTemp;
				}
			}
			sResult = "";
			for (int i = 0; i < strTemp.length; i++) {
				sResult = sResult + strTemp[i] + ",";
			}
			sResult = sResult.substring(0, sResult.length() - 1);
		}
		return sResult;
	}

	public static void main(String[] args) {
		// String sDate = "2014-10-15 14:45";
		// int iMin = 20;
		// int iMonth = 3;
		// System.out.println(dateAddSecond(sDate, iMin * 60, null));
		// System.out.println(dateAddMonth(sDate, iMonth));
		// String sSecond = CommonBean.longToString(86460l * 60);
		// System.out.println(CommonBean.secondConvertDayHourMin(sSecond));
	}

}